diff --git a/PROMS/VEPROMS.CSLA.Library/ClassDiagram1.cd b/PROMS/VEPROMS.CSLA.Library/ClassDiagram1.cd new file mode 100644 index 00000000..0519ecba --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/ClassDiagram1.cd @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/PROMS/VEPROMS.CSLA.Library/Config/DocVersionConfig.cs b/PROMS/VEPROMS.CSLA.Library/Config/DocVersionConfig.cs new file mode 100644 index 00000000..ed2bb15d --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Config/DocVersionConfig.cs @@ -0,0 +1,1054 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.ComponentModel; +using System.Drawing; +using DescriptiveEnum; + +namespace VEPROMS.CSLA.Library +{ + [Serializable] + [TypeConverter(typeof(ExpandableObjectConverter))] + public class DocVersionConfig : DynamicTypeDescriptor, INotifyPropertyChanged + { + public event PropertyChangedEventHandler PropertyChanged; + private void OnPropertyChanged(String info) + { + if (PropertyChanged != null) + PropertyChanged(this, new PropertyChangedEventArgs(info)); + } + internal override bool IsReadOnly + { + get { return _DocVersion == null; } + } + private XMLProperties _Xp; + private XMLProperties Xp + { + get { return _Xp; } + } + public bool ParentLookup + { + get { return _Xp.ParentLookup; } + set { _Xp.ParentLookup = value; } + } + private bool _AncestorLookup; + public bool AncestorLookup + { + get { return _AncestorLookup; } + set { _AncestorLookup = value; } + } + private DocVersion _DocVersion; + public DocVersionConfig(DocVersion docVersion) + { + _DocVersion = docVersion; + string xml = docVersion.Config; + if (xml == string.Empty) xml = ""; + _Xp = new XMLProperties(xml); + if (docVersion.MyFolder != null) _Xp.LookInAncestor += new XMLPropertiesEvent(Xp_LookInAncestorFolder); + } + private string Xp_LookInAncestorFolder(object sender, XMLPropertiesArgs args) + { + if (_AncestorLookup || ParentLookup) + { + for (Folder folder = _DocVersion.MyFolder; folder != null; folder = folder.MyParent) + { + string retval = folder.FolderConfig.GetValue(args.Group, args.Item); + if (retval != string.Empty) return retval; + } + } + return string.Empty; + } + private string Xp_LookInAncestorFolderInfo(object sender, XMLPropertiesArgs args) + { + if (_AncestorLookup || ParentLookup) + { + for (FolderInfo folder = _DocVersionInfo.MyFolder; folder != null; folder = folder.MyParent) + { + string retval = folder.FolderConfig.GetValue(args.Group, args.Item); + if (retval != string.Empty) return retval; + } + } + return string.Empty; + } + private DocVersionInfo _DocVersionInfo; + public DocVersionConfig(DocVersionInfo docVersionInfo) + { + _DocVersionInfo = docVersionInfo; + string xml = docVersionInfo.Config; + if (xml == string.Empty) xml = ""; + _Xp = new XMLProperties(xml); + } + public DocVersionConfig(string xml) + { + _Xp = new XMLProperties(xml); + } + public DocVersionConfig() + { + string xml = ""; + _Xp = new XMLProperties(xml); + } + internal string GetValue(string group, string item) + { + return _Xp[group, item]; + } + //[Category("Identification")] + [Category("General")] + [DisplayName("Name")] + [Description("Name")] + public string Name + { + get { return (_DocVersion != null ? _DocVersion.Name : _DocVersionInfo.Name); } + set { if (_DocVersion != null) _DocVersion.Name = value; } + } + //[Category("Identification")] + [Category("General")] + [DisplayName("Title")] + [Description("Title")] + public string Title + { + get { return (_DocVersion != null ? _DocVersion.Title : _DocVersionInfo.Title); } + set { if (_DocVersion != null) _DocVersion.Title = value; } + } + //[Category("Format")] + [Category("Format Settings")] + [DisplayName("Format")] + [Description("Format")] + [TypeConverter(typeof(FormatList))] + public string FormatSelection + { + get + { + //if (_DocVersion != null) return FormatList.ToString(_DocVersion.FormatID); + //if (_DocVersionInfo != null) return FormatList.ToString(_DocVersionInfo.FormatID); + if (_DocVersion != null && _DocVersion.MyFormat != null) return _DocVersion.MyFormat.PlantFormat.FormatData.Name; + if (_DocVersionInfo != null && _DocVersionInfo.MyFormat != null) return _DocVersionInfo.MyFormat.PlantFormat.FormatData.Name; + return null; + } + set + { + if (_DocVersion != null) _DocVersion.MyFormat = FormatList.ToFormat(value); // Can only be set if _DocVersion is set + } + } + //[Category("Format")] + [Category("Format Settings")] + [DisplayName("Default Format")] + [Description("Format")] + [TypeConverter(typeof(FormatList))] + public string DefaultFormatSelection + { + get + { + //if (_DocVersion != null) return FormatList.ToString(_DocVersion.FormatID); + //if (_DocVersionInfo != null) return FormatList.ToString(_DocVersionInfo.FormatID); + if (_DocVersion != null && _DocVersion.MyFolder != null && _DocVersion.MyFolder.ActiveParent != null) return _DocVersion.MyFolder.ActiveFormat.PlantFormat.FormatData.Name; + if (_DocVersionInfo != null && _DocVersionInfo.MyFolder != null && _DocVersionInfo.MyFolder.ActiveParent != null) return _DocVersionInfo.MyFolder.ActiveFormat.PlantFormat.FormatData.Name; + return null; + } + } + public override string ToString() + { + string s = _Xp.ToString(); + if (s == "" || s == "") return string.Empty; + return s; + } + + // + + #region RODefaults // From proc.ini + //[Category("RODefaults")] + [Category("Referenced Objects")] + //[DisplayName("Setpoint Prefix")] + [DisplayName("Default RO Prefix")] + [RefreshProperties(RefreshProperties.All)] + [Description("Setpoint Prefix")] + public string RODefaults_setpointprefix + { + get + { + return _Xp["RODefaults", "Setpoint"]; + } + set + { + _Xp["RODefaults", "Setpoint"] = value; + OnPropertyChanged("RODefaults_setpointprefix"); + } + } + //[Category("RODefaults")] + [Category("Referenced Objects")] + //[DisplayName("Graphics Prefix")] + [DisplayName("Default Graphics Prefix")] + [RefreshProperties(RefreshProperties.All)] + [Description("Graphics Prefix")] + public string RODefaults_graphicsprefix + { + get + { + return _Xp["RODefaults", "Graphics"]; + } + set + { + _Xp["RODefaults", "Graphics"] = value; + OnPropertyChanged("RODefaults_graphicsprefix"); + } + } + //[Category("Graphics")] + [Category("Referenced Objects")] + //[DisplayName("Default File Extension")] + [DisplayName("Graphic File Extension")] + [RefreshProperties(RefreshProperties.All)] + [Description("Default File Extension")] + public string Graphics_defaultext + { + get + { + return _Xp["Graphics", "defaultext"]; + } + set + { + _Xp["Graphics", "defaultext"] = value; + OnPropertyChanged("Graphics_defaultext"); + } + } + #endregion + #region PrintSettingsCategory // From curset.dat + [Category("Print Settings")] + [DisplayName("Number of Copies")] + [RefreshProperties(RefreshProperties.All)] + [Description("Number of Copies")] + public int Print_NumCopies + { + get + { + string s = _Xp["PrintSettings", "numcopies"]; + if (s == string.Empty) return 1; + return int.Parse(_Xp["PrintSettings", "numcopies"]); + } + set + { + _Xp["PrintSettings", "numcopies"] = value.ToString(); + OnPropertyChanged("Print_NumCopies"); + } + } + [Category("Print Settings")] + [DisplayName("Printer")] + [RefreshProperties(RefreshProperties.All)] + [Description("Printer")] + public string Print_Printer + { + get + { + string s = _Xp["PrintSettings", "Printer"]; + return s; + } + set + { + _Xp["PrintSettings", "Printer"] = value.ToString(); + OnPropertyChanged("Print_Printer"); + } + } + //public enum PrintWatermark : int + //{ + // None = 0, Reference, Draft, Master, Sample, + // [Description("Information Only")] + // InformationOnly + //} + [TypeConverter(typeof(EnumDescConverter))] + public enum PrintWatermark : int + { + None = 0, Reference, Draft, Master, Sample, + [Description("Information Only")] + InformationOnly + } + //[TypeConverter(typeof(EnumDescConverter))] + + [Category("Print Settings")] + [DisplayName("Watermark")] + [RefreshProperties(RefreshProperties.All)] + [Description("Watermark")] + public PrintWatermark Print_Watermark + { + get + { + string s = _Xp["PrintSettings", "Watermark"]; + if (s == string.Empty || s.Equals("-1")) return PrintWatermark.Draft; + return (PrintWatermark)int.Parse(_Xp["PrintSettings", "Watermark"]); + } + set + { + if (value == PrintWatermark.Draft) _Xp["PrintSettings", "Watermark"] = string.Empty; + else _Xp["PrintSettings", "Watermark"] = ((int)value).ToString(); + OnPropertyChanged("Print_Watermark"); + } + } + [Category("Print Settings")] + //[DisplayName("Disable Duplex Printing")] + [DisplayName("Disable Automatic Duplexing")] + [RefreshProperties(RefreshProperties.All)] + [Description("Disable Duplex Printing")] + public bool Print_DisableDuplex + { + get + { + string s = _Xp["PrintSettings", "disableduplex"]; + if (s == string.Empty) return false; + return bool.Parse(_Xp["PrintSettings", "disableduplex"]); + } + set + { + _Xp["PrintSettings", "disableduplex"] = value.ToString(); + OnPropertyChanged("Print_DisableDuplex"); + } + } + // Change Bar Use from 16-bit code: + // No Default + // Without Change Bars + // With Default Change Bars + // With User Specified Change Bars + //public enum PrintChangeBar : int + //{ + // NoDefault = 0, Without, WithDefault, WithUserSpecified + //} + [TypeConverter(typeof(EnumDescConverter))] + public enum PrintChangeBar : int + { + [Description("Select Before Printing")] + SelectBeforePrinting = 0, + [Description("Without Change Bars")] + Without, + [Description("With Default Change Bars")] + WithDefault, + [Description("Use Custom Change Bars")] + WithUserSpecified + } + + //[Category("Print Settings")] + [Category("Format Settings")] + //[DisplayName("Change Bar")] + [DisplayName("Change Bars")] + [RefreshProperties(RefreshProperties.All)] + [Description("Change Bar Use")] + public PrintChangeBar Print_ChangeBar + { + get + { + string s = _Xp["PrintSettings", "ChangeBar"]; + if (s == string.Empty || s.Equals("-1")) return PrintChangeBar.SelectBeforePrinting;//PrintChangeBar.NoDefault; + return (PrintChangeBar)int.Parse(_Xp["PrintSettings", "ChangeBar"]); + } + set + { + //if (value == PrintChangeBar.NoDefault) _Xp["PrintSettings", "ChangeBar"] = string.Empty; + if (value == PrintChangeBar.SelectBeforePrinting) _Xp["PrintSettings", "ChangeBar"] = string.Empty; + else _Xp["PrintSettings", "ChangeBar"] = ((int)value).ToString(); + OnPropertyChanged("Print_ChangeBar"); + } + } + //public string Print_ChangeBarstr + //{ + // get + // { + // return EnumDescConverter.GetEnumDescription( + // string s = _Xp["PrintSettings", "ChangeBar"]; + // if (s == string.Empty) return PrintChangeBar.SelectBeforePrinting;//PrintChangeBar.NoDefault; + // return (PrintChangeBar)int.Parse(_Xp["PrintSettings", "ChangeBar"]); + + // } + //} + // User Specified Change Bar Location from16-bit code: + // With Text + // Outside Box + // AER on LEFT, RNO on Right + // To the Left of Text + [TypeConverter(typeof(EnumDescConverter))] + public enum PrintChangeBarLoc : int + { + [Description("With Text")] + WithText = 0, + [Description("Outside Box")] + OutsideBox, + [Description("AER on Left RNO on Right")] + AERleftRNOright, + [Description("To the Left of the Text")] + LeftOfText + } + //[Category("Print Settings")] + [Category("Format Settings")] + //[DisplayName("Change Bar Location")] + [DisplayName("Change Bar Position")] + [RefreshProperties(RefreshProperties.All)] + [Description("User Specified Change Bar Location")] + public PrintChangeBarLoc Print_ChangeBarLoc + { + get + { + string s = _Xp["PrintSettings", "ChangeBarLoc"]; + if (s == string.Empty || s.Equals("-1")) return PrintChangeBarLoc.WithText; + return (PrintChangeBarLoc)int.Parse(_Xp["PrintSettings", "ChangeBarLoc"]); + } + set + { + if (value == PrintChangeBarLoc.WithText) _Xp["PrintSettings", "ChangeBarLoc"] = string.Empty; + else _Xp["PrintSettings", "ChangeBarLoc"] = ((int)value).ToString(); + OnPropertyChanged("Print_ChangeBarLoc"); + } + } + + // Change Bar Text from16-bit code: + // Date and Change ID + // Revision Number + // Change ID + // No Change Bar Message + // User Defined Message + //public enum PrintChangeBarText : int + //{ + // DateChgID = 0, RevNum, ChgID, None, UserDef + //} + [TypeConverter(typeof(EnumDescConverter))] + public enum PrintChangeBarText : int + { + [Description("Date and Change ID")] + DateChgID = 0, + [Description("Revision Number")] + RevNum, + [Description("Change ID")] + ChgID, + [Description("No Change Bar Text")] + None, + [Description("Custom Change Bar Text")] + UserDef + } + //[Category("Print Settings")] + [Category("Format Settings")] + //[DisplayName("Change Bar Text")] + [DisplayName("Change Bar Text Type")] + [Description("Change Bar Text")] + public PrintChangeBarText Print_ChangeBarText + { + get + { + string s = _Xp["PrintSettings", "ChangeBarText"]; + if (s == string.Empty || s.Equals("-1")) return PrintChangeBarText.DateChgID; + return (PrintChangeBarText)int.Parse(_Xp["PrintSettings", "ChangeBarText"]); + } + set + { + if (value == PrintChangeBarText.DateChgID) _Xp["PrintSettings", "ChangeBarText"] = string.Empty; + else _Xp["PrintSettings", "ChangeBarText"] = ((int)value).ToString(); + OnPropertyChanged("Print_ChangeBarText"); + } + } + //[Category("Print Settings")] + [Category("Format Settings")] + //[DisplayName("User Change Bar Message1")] + [DisplayName("Custom Change Bar Message Line One")] + [RefreshProperties(RefreshProperties.All)] + [Description("User Change Bar Message1")] + public string Print_UserCBMess1 + { + get + { + return _Xp["PrintSettings", "usercbmess1"]; + } + set + { + _Xp["PrintSettings", "usercbmess1"] = value; + OnPropertyChanged("Print_UserCBMess1"); + } + } + //[Category("Print Settings")] + [Category("Format Settings")] + //[DisplayName("User Change Bar Message2")] + [DisplayName("Custom Change Bar Message Line Two")] + [RefreshProperties(RefreshProperties.All)] + [Description("User Change Bar Message2")] + public string Print_UserCBMess2 + { + get + { + return _Xp["PrintSettings", "usercbmess2"]; + } + set + { + _Xp["PrintSettings", "usercbmess2"] = value; + OnPropertyChanged("Print_UserCBMess2"); + } + } + [Category("Print Settings")] + [DisplayName("User Format")] + [RefreshProperties(RefreshProperties.All)] + [Description("User Format")] + public string Print_UserFormat + { + get + { + return _Xp["PrintSettings", "userformat"]; + } + set + { + _Xp["PrintSettings", "userformat"] = value; + OnPropertyChanged("Print_UserFormat"); + } + } + public enum PrintPagination : int + { + Free = 0, Fixed, Auto + } + [Category("Print Settings")] + [DisplayName("Pagination")] + [RefreshProperties(RefreshProperties.All)] + [Description("Pagination")] + public PrintPagination Print_Pagination + { + get + { + string s = _Xp["PrintSettings", "Pagination"]; + if (s == string.Empty || s.Equals("-1")) return PrintPagination.Auto; + return (PrintPagination)int.Parse(_Xp["PrintSettings", "Pagination"]); + } + set + { + if (value == PrintPagination.Auto) _Xp["PrintSettings", "Pagination"] = string.Empty; + else _Xp["PrintSettings", "Pagination"] = ((int)value).ToString(); + OnPropertyChanged("Print_Pagination"); + } + } + #endregion + /* + #region ColorCategory // From veproms.ini + // Note that not all possibilities from 16-bit will be added here, until + // it is determined how these will be used + [Category("Color")] + [DisplayName("ro")] + [RefreshProperties(RefreshProperties.All)] + [Description("ro")] + public string Color_ro + { + get + { + return _Xp["Color", "ro"]; + } + set + { + _Xp["Color", "ro"] = value; + OnPropertyChanged("Color_ro"); + } + } + [Category("Color")] + [DisplayName("editbackground")] + [RefreshProperties(RefreshProperties.All)] + [Description("editbackground")] + public string Color_editbackground + { + get + { + return _Xp["Color", "editbackground"]; + } + set + { + _Xp["Color", "editbackground"] = value; + OnPropertyChanged("Color_editbackground"); + } + } + [Category("Color")] + [DisplayName("black")] + [RefreshProperties(RefreshProperties.All)] + [Description("black")] + public string Color_black + { + get + { + return _Xp["Color", "black"]; + } + set + { + _Xp["Color", "black"] = value; + OnPropertyChanged("Color_black"); + } + } + [Category("Color")] + [DisplayName("blue")] + [RefreshProperties(RefreshProperties.All)] + [Description("blue")] + public string Color_blue + { + get + { + return _Xp["Color", "blue"]; + } + set + { + _Xp["Color", "blue"] = value; + OnPropertyChanged("Color_blue"); + } + } + #endregion // From veproms.ini + #region SystemPrintCategory // From veproms.ini + [Category("System Print")] + [DisplayName("Underline Width")] + [RefreshProperties(RefreshProperties.All)] + [Description("Underline Width")] + public int SysPrint_UWidth + { + get + { + string s = _Xp["SystemPrint", "UnderlineWidth"]; + if (s == string.Empty) return 10; + return int.Parse(_Xp["SystemPrint", "UnderlineWidth"]); + } + set + { + _Xp["SystemPrint", "UnderlineWidth"] = value.ToString(); + OnPropertyChanged("SysPrint_UWidth"); + } + } + [Category("System Print")] + [DisplayName("Vertical Offset")] + [RefreshProperties(RefreshProperties.All)] + [Description("Vertical Offset")] + public int SysPrint_VOffset + { + get + { + string s = _Xp["SystemPrint", "VerticalOffset"]; + if (s == string.Empty) return 0; + return int.Parse(_Xp["SystemPrint", "VerticalOffset"]); + } + set + { + _Xp["SystemPrint", "VerticalOffset"] = value.ToString(); + OnPropertyChanged("SysPrint_VOffset"); + } + } + [Category("System Print")] + [DisplayName("Stroke Width")] + [RefreshProperties(RefreshProperties.All)] + [Description("Stroke Width")] + public int SysPrint_StrokeWidth + { + get + { + string s = _Xp["SystemPrint", "StrokeWidth"]; + if (s == string.Empty) return 0; + return int.Parse(_Xp["SystemPrint", "StrokeWidth"]); + } + set + { + _Xp["SystemPrint", "StrokeWidth"] = value.ToString(); + OnPropertyChanged("SysPrint_StrokeWidth"); + } + } + [Category("System Print")] + [DisplayName("Stroke Width Bold")] + [RefreshProperties(RefreshProperties.All)] + [Description("Stroke Width Bold")] + public int SysPrint_StrokeWidthBold + { + get + { + string s = _Xp["SystemPrint", "StrokeWidthBold"]; + if (s == string.Empty) return 0; + return int.Parse(_Xp["SystemPrint", "StrokeWidthBold"]); + } + set + { + _Xp["SystemPrint", "StrokeWidthBold"] = value.ToString(); + OnPropertyChanged("SysPrint_StrokeWidthBold"); + } + } + #endregion + #region StartupCategory // From veproms.ini + [Category("Startup")] + [DisplayName("Startup MessageBox Title")] + [RefreshProperties(RefreshProperties.All)] + [Description("Startup MessageBox Title")] + public string Startup_MsgTitle + { + get + { + return _Xp["Startup", "MessageBoxTitle"]; + } + set + { + _Xp["Startup", "MessageBoxTitle"] = value; + OnPropertyChanged("Startup_MsgTitle"); + } + } + [Category("Startup")] + [DisplayName("Startup Message File")] + [RefreshProperties(RefreshProperties.All)] + [Description("Startup Message File")] + public string Startup_MsgFile + { + get + { + return _Xp["Startup", "MessageFile"]; + } + set + { + _Xp["Startup", "MessageFile"] = value; + OnPropertyChanged("Startup_MsgFile"); + } + } + #endregion + #region ProcedureListTabStopsCategory // From veproms.ini + [Category("ProcedureListTabStops")] + [DisplayName("Procedure Number Tab")] + [RefreshProperties(RefreshProperties.All)] + [Description("Procedure Number Tab")] + public int ProcListTab_Number + { + get + { + string s = _Xp["ProcedureListTabStops", "ProcedureNumberTab"]; + if (s == string.Empty) return 75; + return int.Parse(_Xp["ProcedureListTabStops", "ProcedureNumberTab"]); + } + set + { + _Xp["ProcedureListTabStops", "ProcedureNumberTab"] = value.ToString(); + OnPropertyChanged("ProcListTab_Number"); + } + } + [Category("ProcedureListTabStops")] + [DisplayName("Procedure Title Tab")] + [RefreshProperties(RefreshProperties.All)] + [Description("Procedure Title Tab")] + public int ProcListTab_Title + { + get + { + string s = _Xp["ProcedureListTabStops", "ProcedureTitleTab"]; + if (s == string.Empty) return 175; + return int.Parse(_Xp["ProcedureListTabStops", "ProcedureTitleTab"]); + } + set + { + _Xp["ProcedureListTabStops", "ProcedureTitleTab"] = value.ToString(); + OnPropertyChanged("ProcListTab_Title"); + } + } + #endregion + #region FormatCategory + public enum FormatColumns : int + { + Default=0,OneColumn,TwoColumn,ThreeColumn,FourColumns + } + [Category("Format")] + [DisplayName("Column Layout")] + [RefreshProperties(RefreshProperties.All)] + [Description("Column Layout")] + public FormatColumns Format_Columns + { + get + { + string s = _Xp["format", "columns"]; + if (s == string.Empty) return (FormatColumns)0; + return (FormatColumns)int.Parse(_Xp["format", "columns"]); + //return Enum.Parse(typeof(FormatColumns),_Xp["format", "columns"]); + } + set + { + if (value == 0) _Xp["format", "columns"] = string.Empty; + else _Xp["format", "columns"] = ((int)value).ToString(); + OnPropertyChanged("Format_Columns"); + } + } + [Category("Format")] + [DisplayName("Plant Format Name")] + [RefreshProperties(RefreshProperties.All)] + [Description("Default Plant Format")] + public string Format_Plant + { + get + { return _Xp["format", "plant"]; + } + set + { + _Xp["format", "plant"] = value; + OnPropertyChanged("Format_Plant"); + } + } + #endregion + #region DefaultsCategory // from proc.ini + [Category("Defaults")] + [DisplayName("Default Setpoint Prefix")] + [RefreshProperties(RefreshProperties.All)] + [Description("Default Setpoint Prefix")] + public string Default_SPPrefix + { + get { return _Xp["default", "spprefix"]; } + set + { + _Xp["default", "spprefix"] = value; + OnPropertyChanged("Default_SPPrefix"); + } + } + [Category("Defaults")] + [DisplayName("Default Image Prefix")] + [RefreshProperties(RefreshProperties.All)] + [Description("Default Image Prefix")] + public string Default_IMPrefix + { + get { return _Xp["default", "imprefix"]; } + set + { + _Xp["default", "imprefix"] = value; + OnPropertyChanged("RO_IMPrefix"); + } + } + #endregion + #region PrintSettingsCategory // From curset.dat + [Category("Print Settings")] + [DisplayName("Number of Copies")] + [RefreshProperties(RefreshProperties.All)] + [Description("Number of Copies")] + public int Print_NumCopies + { + get + { + string s = _Xp["PrintSettings", "numcopies"]; + if (s == string.Empty) return 1; + return int.Parse(_Xp["PrintSettings", "numcopies"]); + } + set + { + _Xp["PrintSettings", "numcopies"] = value.ToString(); + OnPropertyChanged("Print_NumCopies"); + } + } + public enum PrintPagination : int + { + Free = 0, Fixed, Auto + } + [Category("Print Settings")] + [DisplayName("Pagination")] + [RefreshProperties(RefreshProperties.All)] + [Description("Pagination")] + public PrintPagination Print_Pagination + { + get + { + string s = _Xp["PrintSettings", "Pagination"]; + if (s == string.Empty) return PrintPagination.Auto; + return (PrintPagination)int.Parse(_Xp["PrintSettings", "Pagination"]); + } + set + { + if (value == PrintPagination.Auto) _Xp["PrintSettings", "Pagination"] = string.Empty; + else _Xp["PrintSettings", "Pagination"] = ((int)value).ToString(); + OnPropertyChanged("Print_Pagination"); + } + } + public enum PrintWatermark : int + { + None = 0, Reference, Draft, Master, Sample, InformationOnly + } + [Category("Print Settings")] + [DisplayName("Watermark")] + [RefreshProperties(RefreshProperties.All)] + [Description("Watermark")] + public PrintWatermark Print_Watermark + { + get + { + string s = _Xp["PrintSettings", "Watermark"]; + if (s == string.Empty) return PrintWatermark.Draft; + return (PrintWatermark)int.Parse(_Xp["PrintSettings", "Watermark"]); + } + set + { + if (value == PrintWatermark.Draft) _Xp["PrintSettings", "Watermark"] = string.Empty; + else _Xp["PrintSettings", "Watermark"] = ((int)value).ToString(); + OnPropertyChanged("Print_Watermark"); + } + } + [Category("Print Settings")] + [DisplayName("Disable Duplex Printing")] + [RefreshProperties(RefreshProperties.All)] + [Description("Disable Duplex Printing")] + public bool Print_DisableDuplex + { + get + { + string s = _Xp["PrintSettings", "disableduplex"]; + if (s == string.Empty) return false; + return bool.Parse(_Xp["PrintSettings", "disableduplex"]); + } + set + { + _Xp["PrintSettings", "disableduplex"] = value.ToString(); + OnPropertyChanged("Print_DisableDuplex"); + } + } + // Change Bar Use from 16-bit code: + // No Default + // Without Change Bars + // With Default Change Bars + // With User Specified Change Bars + public enum PrintChangeBar : int + { + NoDefault=0, Without, WithDefault, WithUserSpecified + } + [Category("Print Settings")] + [DisplayName("Change Bar")] + [RefreshProperties(RefreshProperties.All)] + [Description("Change Bar Use")] + public PrintChangeBar Print_ChangeBar + { + get + { + string s = _Xp["PrintSettings", "ChangeBar"]; + if (s == string.Empty) return PrintChangeBar.NoDefault; + return (PrintChangeBar)int.Parse(_Xp["PrintSettings", "ChangeBar"]); + } + set + { + if (value == PrintChangeBar.NoDefault) _Xp["PrintSettings", "ChangeBar"] = string.Empty; + else _Xp["PrintSettings", "ChangeBar"] = ((int)value).ToString(); + OnPropertyChanged("Print_ChangeBar"); + } + } + // User Specified Change Bar Location from16-bit code: + // With Text + // Outside Box + // AER on LEFT, RNO on Right + // To the Left of Text + public enum PrintChangeBarLoc : int + { + WithText = 0, OutsideBox, AERleftRNOright, LeftOfText + } + [Category("Print Settings")] + [DisplayName("Change Bar Location")] + [RefreshProperties(RefreshProperties.All)] + [Description("User Specified Change Bar Location")] + public PrintChangeBarLoc Print_ChangeBarLoc + { + get + { + string s = _Xp["PrintSettings", "ChangeBarLoc"]; + if (s == string.Empty) return PrintChangeBarLoc.WithText; + return (PrintChangeBarLoc)int.Parse(_Xp["PrintSettings", "ChangeBarLoc"]); + } + set + { + if (value == PrintChangeBarLoc.WithText) _Xp["PrintSettings", "ChangeBarLoc"] = string.Empty; + else _Xp["PrintSettings", "ChangeBarLoc"] = ((int)value).ToString(); + OnPropertyChanged("Print_ChangeBarLoc"); + } + } + + // Change Bar Text from16-bit code: + // Date and Change ID + // Revision Number + // Change ID + // No Change Bar Message + // User Defined Message + public enum PrintChangeBarText : int + { + DateChgID = 0, RevNum, ChgID, None, UserDef + } + [Category("Print Settings")] + [DisplayName("Change Bar Text")] + [RefreshProperties(RefreshProperties.All)] + [Description("Change Bar Text")] + public PrintChangeBarText Print_ChangeBarText + { + get + { + string s = _Xp["PrintSettings", "ChangeBarText"]; + if (s == string.Empty) return PrintChangeBarText.DateChgID; + return (PrintChangeBarText)int.Parse(_Xp["PrintSettings", "ChangeBarText"]); + } + set + { + if (value == PrintChangeBarText.DateChgID) _Xp["PrintSettings", "ChangeBarText"] = string.Empty; + else _Xp["PrintSettings", "ChangeBarText"] = ((int)value).ToString(); + OnPropertyChanged("Print_ChangeBarText"); + } + } + + [Category("Print Settings")] + [DisplayName("User Format")] + [RefreshProperties(RefreshProperties.All)] + [Description("User Format")] + public string Print_UserFormat + { + get + { + return _Xp["PrintSettings", "userformat"]; + } + set + { + _Xp["PrintSettings", "userformat"] = value; + OnPropertyChanged("Print_UserFormat"); + } + } + + [Category("Print Settings")] + [DisplayName("User Change Bar Message1")] + [RefreshProperties(RefreshProperties.All)] + [Description("User Change Bar Message1")] + public string Print_UserCBMess1 + { + get + { + return _Xp["PrintSettings", "usercbmess1"]; + } + set + { + _Xp["PrintSettings", "usercbmess1"] = value; + OnPropertyChanged("Print_UserCBMess1"); + } + } + + [Category("Print Settings")] + [DisplayName("User Change Bar Message2")] + [RefreshProperties(RefreshProperties.All)] + [Description("User Change Bar Message2")] + public string Print_UserCBMess2 + { + get + { + return _Xp["PrintSettings", "usercbmess2"]; + } + set + { + _Xp["PrintSettings", "usercbmess2"] = value; + OnPropertyChanged("Print_UserCBMess2"); + } + } + #endregion +[Category("Defaults")] +[DisplayName("Default BackColor")] +[RefreshProperties(RefreshProperties.All)] +[Description("Default Background Color")] +public Color Default_BkColor +{ +get +{ +//return _Xp["default", "BkColor"]; +string sColor = _Xp["default", "BkColor"]; +if (sColor == string.Empty) sColor = "White"; +if (sColor[0] == '[') +{ +string[] parts = sColor.Substring(1, sColor.Length - 2).Split(",".ToCharArray()); +return Color.FromArgb(Int32.Parse(parts[0]), Int32.Parse(parts[1]), Int32.Parse(parts[2])); +} +else return Color.FromName(sColor); +} +set +{ +if (value.IsNamedColor) _Xp["default", "BkColor"] = value.Name; +else +{ +_Xp["default", "BkColor"] = string.Format("[{0},{1},{2}]", value.R, value.G, value.B); +} +OnPropertyChanged("Default_BkColor"); + +} +} +} +} +*/ + } +} \ No newline at end of file diff --git a/PROMS/VEPROMS.CSLA.Library/Config/DynamicProperties.cs b/PROMS/VEPROMS.CSLA.Library/Config/DynamicProperties.cs new file mode 100644 index 00000000..0237c94e --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Config/DynamicProperties.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.ComponentModel; + +namespace VEPROMS.CSLA.Library +{ + public class DynamicPropertyDescriptor : PropertyDescriptor + { + private PropertyDescriptor _BasePropertyDescriptor; + private DynamicTypeDescriptor _Instance; + + public DynamicPropertyDescriptor(DynamicTypeDescriptor instance, PropertyDescriptor basePropertyDescriptor) + : base(basePropertyDescriptor) + { + _Instance = instance; + _BasePropertyDescriptor = basePropertyDescriptor; + } + public override bool CanResetValue(object component) + { return _BasePropertyDescriptor.CanResetValue(component); } + public override Type ComponentType + { get { return _BasePropertyDescriptor.ComponentType; } } + public override object GetValue(object component) + { return _BasePropertyDescriptor.GetValue(component); } + public override bool IsReadOnly + { get { return _Instance.IsReadOnly; } } + public override Type PropertyType + { get { return _BasePropertyDescriptor.PropertyType; } } + public override void ResetValue(object component) + { _BasePropertyDescriptor.ResetValue(component); } + public override bool ShouldSerializeValue(object component) + { return _BasePropertyDescriptor.ShouldSerializeValue(component); } + public override void SetValue(object component, object value) + { _BasePropertyDescriptor.SetValue(component, value); } + } + [Serializable()] + public class DynamicTypeDescriptor //: ICustomTypeDescriptor//, ISupportInitialize + { + [NonSerialized] + private PropertyDescriptorCollection dynamicProps; + private bool _IsReadOnly = false; + internal virtual bool IsReadOnly + { + get { return _IsReadOnly; } + set { _IsReadOnly = value; } + } + public DynamicTypeDescriptor() { } + #region "TypeDescriptor Implementation" + 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 PropertyDescriptorCollection GetProperties(Attribute[] attributes) + { + return GetProperties(); + } + public PropertyDescriptorCollection GetProperties() + { + if (dynamicProps == null) + { + PropertyDescriptorCollection baseProps = TypeDescriptor.GetProperties(this, true); + dynamicProps = new PropertyDescriptorCollection(null); + + foreach (PropertyDescriptor oProp in baseProps) + { + dynamicProps.Add(new DynamicPropertyDescriptor(this, oProp)); + } + } + return dynamicProps; + } + public object GetPropertyOwner(PropertyDescriptor pd) + { return this; } + #endregion + } +} diff --git a/PROMS/VEPROMS.CSLA.Library/Config/EnumDescConverter.cs b/PROMS/VEPROMS.CSLA.Library/Config/EnumDescConverter.cs new file mode 100644 index 00000000..468807a5 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Config/EnumDescConverter.cs @@ -0,0 +1,164 @@ +/***************************************************************** + * Module: EnumDescConverter.cs + * Type: C# Source Code + * Version: 1.0 + * Description: Enum Converter using Description Attributes + * + * Revisions + * ------------------------------------------------ + * [F] 24/02/2004, Jcl - Shaping up + * [B] 25/02/2004, Jcl - Made it much easier :-) + * + *****************************************************************/ + +using System; +using System.ComponentModel; +using System.Drawing; +using System.Drawing.Design; +using System.Reflection; +using System.Collections; +using System.Data; + +namespace DescriptiveEnum +{ + /// + /// EnumConverter supporting System.ComponentModel.DescriptionAttribute + /// + public class EnumDescConverter : System.ComponentModel.EnumConverter + { + protected System.Type myVal; + + /// + /// Gets Enum Value's Description Attribute + /// + /// The value you want the description attribute for + /// The description, if any, else it's .ToString() + public static string GetEnumDescription(Enum value) + { + Console.WriteLine("{0}", value); + FieldInfo fi = value.GetType().GetField(value.ToString()); + DescriptionAttribute[] attributes = + (DescriptionAttribute[])fi.GetCustomAttributes( + typeof(DescriptionAttribute), false); + //Console.WriteLine("{0},{1},{2}", value.ToString(), attributes.Length, (attributes.Length > 0) ? attributes[0].Description : value.ToString()); + return (attributes.Length>0)?attributes[0].Description:value.ToString(); + } + + /// + /// Gets the description for certaing named value in an Enumeration + /// + /// The type of the Enumeration + /// The name of the Enumeration value + /// The description, if any, else the passed name + public static string GetEnumDescription(System.Type value, string name) + { + FieldInfo fi= value.GetField(name); + DescriptionAttribute[] attributes = + (DescriptionAttribute[])fi.GetCustomAttributes( + typeof(DescriptionAttribute), false); + return (attributes.Length>0)?attributes[0].Description:name; + } + + /// + /// Gets the value of an Enum, based on it's Description Attribute or named value + /// + /// The Enum type + /// The description or name of the element + /// The value, or the passed in description, if it was not found + public static object GetEnumValue(System.Type value, string description) + { + FieldInfo [] fis = value.GetFields(); + foreach(FieldInfo fi in fis) + { + DescriptionAttribute[] attributes = + (DescriptionAttribute[])fi.GetCustomAttributes( + typeof(DescriptionAttribute), false); + if(attributes.Length>0) + { + if(attributes[0].Description == description) + { + return fi.GetValue(fi.Name); + } + } + if(fi.Name == description) + { + return fi.GetValue(fi.Name); + } + } + return description; + } + + public EnumDescConverter(System.Type type) : base(type.GetType()) + { + myVal = type; + } + + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) + { + if(value is Enum && destinationType == typeof(string)) + { + return EnumDescConverter.GetEnumDescription((Enum)value); + } + if(value is string && destinationType == typeof(string)) + { + return EnumDescConverter.GetEnumDescription(myVal, (string)value); + } + return base.ConvertTo (context, culture, value, destinationType); + } + + public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + if(value is string) + { + return EnumDescConverter.GetEnumValue(myVal, (string)value); + } + if(value is Enum) + { + return EnumDescConverter.GetEnumDescription((Enum)value); + } + return base.ConvertFrom (context, culture, value); + } + public override bool GetPropertiesSupported(ITypeDescriptorContext context) + { + return true; + } + + public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) + { + ArrayList values = new ArrayList(); + FieldInfo[] fis = myVal.GetFields(); + foreach (FieldInfo fi in fis) + { + DescriptionAttribute[] attributes =(DescriptionAttribute[])fi.GetCustomAttributes( + typeof(DescriptionAttribute), false); + //if (attributes.Length > 0) + if (fi.Name != "value__") + values.Add(fi.GetValue(fi.Name)); + } + return new TypeConverter.StandardValuesCollection(values); + } + public static string GetEnumKeyDescription(Enum value) + { + FieldInfo fi = value.GetType().GetField(value.ToString()); + DescriptionAttribute[] attributes = + (DescriptionAttribute[])fi.GetCustomAttributes( + typeof(DescriptionAttribute), false); + return (attributes.Length > 0) ? attributes[0].Description : value.ToString(); + } + + public static DataTable GetEnumAsDataTable(System.Type EnumType) + { + DataTable DTEnum = new DataTable(); + DTEnum.Columns.Add(new DataColumn("EnumID", typeof(Int32))); + DTEnum.Columns.Add(new DataColumn("Enum", typeof(string))); + DTEnum.Columns.Add(new DataColumn("Description", typeof(string))); + foreach (int i in Enum.GetValues(EnumType)) + { + System.Enum fooItem = (System.Enum)Enum.ToObject(EnumType, i); + DTEnum.Rows.Add(new object[] { i, fooItem.ToString(), GetEnumKeyDescription(fooItem) }); + } + return DTEnum; + } + } + +} \ No newline at end of file diff --git a/PROMS/VEPROMS.CSLA.Library/Config/EnumDetail.cs b/PROMS/VEPROMS.CSLA.Library/Config/EnumDetail.cs new file mode 100644 index 00000000..d983be55 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Config/EnumDetail.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Reflection; +using System.ComponentModel; + +namespace VEPROMS.CSLA.Library +{ + public class EnumDetail + { + private T _EValue; + public T EValue + { + get { return _EValue; } + set { _EValue = value; } + } + private string _Name; + + public string Name + { + get { return _Name; } + set { _Name = value; } + } + public EnumDetail(string name, T eValue) + { + _Name = name; + _EValue = eValue; + } + public static EnumDetail[] Details() + { + string[] names = Enum.GetNames(typeof(T)); + Array values = Enum.GetValues(typeof(T)); + EnumDetail[] retval = new EnumDetail[values.Length]; + for (int i = 0; i < values.Length; i++) + { + T val = (T)values.GetValue(i); + FieldInfo fi = val.GetType().GetField(val.ToString()); + DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false); + retval[i] = new EnumDetail(((attributes.Length > 0) ? attributes[0].Description : names[i]), (T)values.GetValue(i)); + } + return retval; + } + } +} diff --git a/PROMS/VEPROMS.CSLA.Library/Config/FolderConfig.cs b/PROMS/VEPROMS.CSLA.Library/Config/FolderConfig.cs new file mode 100644 index 00000000..ef9e74e5 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Config/FolderConfig.cs @@ -0,0 +1,804 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.ComponentModel; +using System.Drawing; +using DescriptiveEnum; + +namespace VEPROMS.CSLA.Library +{ + [Serializable] + [TypeConverter(typeof(ExpandableObjectConverter))] + //public class FolderConfig : INotifyPropertyChanged + public class FolderConfig : DynamicTypeDescriptor, INotifyPropertyChanged + { + public event PropertyChangedEventHandler PropertyChanged; + private void OnPropertyChanged(String info) + { + if (PropertyChanged != null) + PropertyChanged(this, new PropertyChangedEventArgs(info)); + } + internal override bool IsReadOnly + { + get { return _Folder == null; } + } + private XMLProperties _Xp; + private XMLProperties Xp + { + get { return _Xp; } + } + public bool ParentLookup + { + get { return _Xp.ParentLookup; } + set { _Xp.ParentLookup = value; } + } + [NonSerialized] + private bool _AncestorLookup; + public bool AncestorLookup + { + get { return _AncestorLookup; } + set { _AncestorLookup = value; } + } + private Folder _Folder; + private FolderInfo _FolderInfo; + public FolderConfig(Folder folder) + { + _Folder = folder; + string xml = _Folder.Config; + if (xml == string.Empty) xml = ""; + _Xp = new XMLProperties(xml); + if(folder.MyParent != null) _Xp.LookInAncestor += new XMLPropertiesEvent(Xp_LookInAncestorFolder); + } + private string Xp_LookInAncestorFolder(object sender, XMLPropertiesArgs args) + { + if (_AncestorLookup || ParentLookup) + { + for (Folder folder = _Folder.MyParent; folder != null; folder = folder.MyParent) + { + string retval = folder.FolderConfig.GetValue( args.Group, args.Item); + if (retval != string.Empty) return retval; + } + } + return string.Empty; + } + private string Xp_LookInAncestorFolderInfo(object sender, XMLPropertiesArgs args) + { + if (_AncestorLookup || ParentLookup) + { + for (FolderInfo folder = _FolderInfo.MyParent; folder != null; folder = folder.MyParent) + { + string retval = folder.FolderConfig.GetValue(args.Group, args.Item); + if (retval != string.Empty) return retval; + } + } + return string.Empty; + } + public FolderConfig(FolderInfo folderInfo) + { + _FolderInfo = folderInfo; + string xml = _FolderInfo.Config; + if (xml == string.Empty) xml = ""; + _Xp = new XMLProperties(xml); + } + public FolderConfig(string xml) + { + if (xml == string.Empty) xml = ""; + _Xp = new XMLProperties(xml); + } + public FolderConfig() + { + _Xp = new XMLProperties(""); + } + internal string GetValue(string group, string item) + { + return _Xp[group, item]; + } + //[Category("Identification")] + [Category("General")] + [DisplayName("Name")] + [Description("Name")] + public string Name + { + get { return (_Folder != null ? _Folder.Name : _FolderInfo.Name); } + set { if (_Folder != null)_Folder.Name = value; } + } + //[Category("Identification")] + [Category("General")] + [DisplayName("Title")] + [Description("Title")] + public string Title + { + get { return (_Folder != null ? _Folder.Title : _FolderInfo.Title); } + set { _Folder.Title = value; } + } + //[Category("Identification")] + [Category("General")] + [DisplayName("Short Name")] + [Description("Short Name")] + public string ShortName + { + get { return (_Folder != null ? _Folder.ShortName : _FolderInfo.ShortName); } + set { if (_Folder != null)_Folder.ShortName = value; } + } + //[Category("Format")] + [Category("Format Settings")] + [DisplayName("Format")] + [Description("Format")] + [TypeConverter(typeof(FormatList))] + public string FormatSelection + { + get + { + //if (_Folder != null) return FormatList.ToString(_Folder.FormatID); + //if (_FolderInfo != null) return FormatList.ToString(_FolderInfo.FormatID); + if (_Folder != null && _Folder.MyFormat != null) return _Folder.MyFormat.PlantFormat.FormatData.Name; + if (_FolderInfo != null && _FolderInfo.MyFormat != null) return _FolderInfo.MyFormat.PlantFormat.FormatData.Name; + return null; + } + set + { + if (_Folder != null)_Folder.MyFormat = FormatList.ToFormat(value); + } + } + //[Category("Format")] + [Category("Format Settings")] + [DisplayName("Default Format")] + //[DisplayName("Format")] + [Description("Format")] + [TypeConverter(typeof(FormatList))] + public string DefaultFormatSelection + { + get + { + //if (_Folder != null) return FormatList.ToString(_Folder.FormatID); + //if (_FolderInfo != null) return FormatList.ToString(_FolderInfo.FormatID); + if (_Folder != null && _Folder.MyParent!= null && _Folder.MyParent.ActiveFormat != null) return _Folder.MyParent.ActiveFormat.PlantFormat.FormatData.Name; + if (_FolderInfo != null && _FolderInfo.MyParent != null && _FolderInfo.MyParent.ActiveFormat != null) return _FolderInfo.MyParent.ActiveFormat.PlantFormat.FormatData.Name; + return null; + } + } + public override string ToString() + { + string s = _Xp.ToString(); + if (s == "" || s == "") return string.Empty; + return s; + } + #region GraphicsCategory // From veproms.ini + public bool CanWrite(string str) + { + return true; + } + //[Category("Graphics")] + [Category("Referenced Objects")] + [DisplayName("Graphic File Extension")] + //[DisplayName("Default File Extension")] + [RefreshProperties(RefreshProperties.All)] + [Description("Default File Extension")] + public string Graphics_defaultext + { + get + { + return _Xp["Graphics", "defaultext"]; + } + set + { + _Xp["Graphics", "defaultext"] = value; + OnPropertyChanged("Graphics_defaultext"); + } + } + #endregion + #region ColorCategory // From veproms.ini + // Note that not all possibilities from 16-bit will be added here, until + // it is determined how these will be used + //[Category("Color")] + [Category("Editor Settings")] + //[DisplayName("Referenced Object Highlight")] + [DisplayName("Step Editor Colors - Referenced Objects")] + [RefreshProperties(RefreshProperties.All)] + [Description("Color used to highlight an RO in procedure text")] + public string Color_ro + { + get + { + return _Xp["Color", "ro"]; + } + set + { + _Xp["Color", "ro"] = value; + OnPropertyChanged("Color_ro"); + } + } + //[Category("Color")] + [Category("Editor Settings")] + //[DisplayName("Transition Highlight")] + [DisplayName("Step Editor Colors - Transitions")] + [RefreshProperties(RefreshProperties.All)] + [Description("Color used to highlight a Transition in procedure text")] + public string Color_transition + { + get + { + return _Xp["Color", "transition"]; + } + set + { + _Xp["Color", "transition"] = value; + OnPropertyChanged("Color_transition"); + } + } + //[Category("Color")] + [Category("Editor Settings")] + //[DisplayName("editbackground")] + [DisplayName("Step Editor Colors - Active Background")] + [RefreshProperties(RefreshProperties.All)] + [Description("editbackground")] + public string Color_editbackground + { + get + { + return _Xp["Color", "editbackground"]; + } + set + { + _Xp["Color", "editbackground"] = value; + OnPropertyChanged("Color_editbackground"); + } + } + [Category("Color")] + [DisplayName("black")] + [RefreshProperties(RefreshProperties.All)] + [Description("black")] + public string Color_black + { + get + { + return _Xp["Color", "black"]; + } + set + { + _Xp["Color", "black"] = value; + OnPropertyChanged("Color_black"); + } + } + [Category("Color")] + [DisplayName("blue")] + [RefreshProperties(RefreshProperties.All)] + [Description("blue")] + public string Color_blue + { + get + { + return _Xp["Color", "blue"]; + } + set + { + _Xp["Color", "blue"] = value; + OnPropertyChanged("Color_blue"); + } + } + #endregion // From veproms.ini + #region SystemPrintCategory // From veproms.ini + //[Category("System Print")] + [Category("Print Settings")] + [DisplayName("Override Underline Thickness (dots)")] + //[DisplayName("Underline Width")] + [RefreshProperties(RefreshProperties.All)] + [Description("Underline Width")] + public int SysPrint_UWidth + { + get + { + string s = _Xp["SystemPrint", "UnderlineWidth"]; + if (s == string.Empty) return 10; + return int.Parse(_Xp["SystemPrint", "UnderlineWidth"]); + } + set + { + _Xp["SystemPrint", "UnderlineWidth"] = value.ToString(); + OnPropertyChanged("SysPrint_UWidth"); + } + } + //[Category("System Print")] + [Category("Print Settings")] + [DisplayName("Adjust Starting Print Position (dots)")] + //[DisplayName("Vertical Offset")] + [RefreshProperties(RefreshProperties.All)] + [Description("Vertical Offset")] + public int SysPrint_VOffset + { + get + { + string s = _Xp["SystemPrint", "VerticalOffset"]; + if (s == string.Empty) return 0; + return int.Parse(_Xp["SystemPrint", "VerticalOffset"]); + } + set + { + _Xp["SystemPrint", "VerticalOffset"] = value.ToString(); + OnPropertyChanged("SysPrint_VOffset"); + } + } + //[Category("System Print")] + [Category("Print Settings")] + [DisplayName("Override Normal Pen Width (dots)")] + //[DisplayName("Stroke Width")] + [RefreshProperties(RefreshProperties.All)] + [Description("Stroke Width")] + public int SysPrint_StrokeWidth + { + get + { + string s = _Xp["SystemPrint", "StrokeWidth"]; + if (s == string.Empty) return 0; + return int.Parse(_Xp["SystemPrint", "StrokeWidth"]); + } + set + { + _Xp["SystemPrint", "StrokeWidth"] = value.ToString(); + OnPropertyChanged("SysPrint_StrokeWidth"); + } + } + //[Category("System Print")] + [Category("Print Settings")] + [DisplayName("Override Bold Pen Width (dots)")] + //[DisplayName("Stroke Width Bold")] + [RefreshProperties(RefreshProperties.All)] + [Description("Stroke Width Bold")] + public int SysPrint_StrokeWidthBold + { + get + { + string s = _Xp["SystemPrint", "StrokeWidthBold"]; + if (s == string.Empty) return 0; + return int.Parse(_Xp["SystemPrint", "StrokeWidthBold"]); + } + set + { + _Xp["SystemPrint", "StrokeWidthBold"] = value.ToString(); + OnPropertyChanged("SysPrint_StrokeWidthBold"); + } + } + #endregion + #region StartupCategory // From veproms.ini + //[Category("Startup")] + [Category("Startup Message")] + [DisplayName("Startup MessageBox Title")] + [RefreshProperties(RefreshProperties.All)] + [Description("Startup MessageBox Title")] + public string Startup_MsgTitle + { + get + { + return _Xp["Startup", "MessageBoxTitle"]; + } + set + { + _Xp["Startup", "MessageBoxTitle"] = value; + OnPropertyChanged("Startup_MsgTitle"); + } + } + //[Category("Startup")] + [Category("Startup Message")] + [DisplayName("Startup Message File")] + [RefreshProperties(RefreshProperties.All)] + [Description("Startup Message File")] + public string Startup_MsgFile + { + get + { + return _Xp["Startup", "MessageFile"]; + } + set + { + _Xp["Startup", "MessageFile"] = value; + OnPropertyChanged("Startup_MsgFile"); + } + } + #endregion + #region ProcedureListTabStopsCategory // From veproms.ini + [Category("ProcedureListTabStops")] + [DisplayName("Procedure Number Tab")] + [RefreshProperties(RefreshProperties.All)] + [Description("Procedure Number Tab")] + public int ProcListTab_Number + { + get + { + string s = _Xp["ProcedureListTabStops", "ProcedureNumberTab"]; + if (s == string.Empty) return 75; + return int.Parse(_Xp["ProcedureListTabStops", "ProcedureNumberTab"]); + } + set + { + _Xp["ProcedureListTabStops", "ProcedureNumberTab"] = value.ToString(); + OnPropertyChanged("ProcListTab_Number"); + } + } + [Category("ProcedureListTabStops")] + [DisplayName("Procedure Title Tab")] + [RefreshProperties(RefreshProperties.All)] + [Description("Procedure Title Tab")] + public int ProcListTab_Title + { + get + { + string s = _Xp["ProcedureListTabStops", "ProcedureTitleTab"]; + if (s == string.Empty) return 175; + return int.Parse(_Xp["ProcedureListTabStops", "ProcedureTitleTab"]); + } + set + { + _Xp["ProcedureListTabStops", "ProcedureTitleTab"] = value.ToString(); + OnPropertyChanged("ProcListTab_Title"); + } + } + #endregion + #region FormatCategory + [TypeConverter(typeof(EnumDescConverter))] + public enum FormatColumns : int + { + Default = 0, + [Description("Single Column")]OneColumn, + [Description("Duel Column")]TwoColumn, + [Description("Triple Column")]ThreeColumn, + [Description("Quad Column")]FourColumns + } + //[Category("Format")] + //[DisplayName("Column Layout")] + [Category("Editor Settings")] + [DisplayName("Step Editor Columns")] + [RefreshProperties(RefreshProperties.All)] + [Description("Column Layout")] + public FormatColumns Format_Columns + { + get + { + string s = _Xp["format", "columns"]; + if (s == string.Empty || s.Equals("-1")) return FormatColumns.Default;//return (FormatColumns)0; + return (FormatColumns)int.Parse(_Xp["format", "columns"]); + //return Enum.Parse(typeof(FormatColumns),_Xp["format", "columns"]); + } + set + { + if (value == 0) _Xp["format", "columns"] = string.Empty; + else _Xp["format", "columns"] = ((int)value).ToString(); + OnPropertyChanged("Format_Columns"); + } + } + //[Category("Format")] + //[DisplayName("Plant Format Name")] + [Category("Format Settings")] + [DisplayName("Format")] + [RefreshProperties(RefreshProperties.All)] + [Description("Default Plant Format")] + public string Format_Plant + { + get + { + return _Xp["format", "plant"]; + } + set + { + _Xp["format", "plant"] = value; + OnPropertyChanged("Format_Plant"); + } + } + #endregion + #region DefaultsCategory // from proc.ini + //[Category("Defaults")] + [Category("Referenced Objects")] + //[DisplayName("Default Setpoint Prefix")] + [DisplayName("Default RO Prefix")] + [RefreshProperties(RefreshProperties.All)] + [Description("Default Setpoint Prefix")] + public string Default_SPPrefix + { + get { return _Xp["default", "spprefix"]; } + set + { + _Xp["default", "spprefix"] = value; + OnPropertyChanged("Default_SPPrefix"); + } + } + //[Category("Defaults")] + [Category("Referenced Objects")] + [DisplayName("Default Image Prefix")] + [RefreshProperties(RefreshProperties.All)] + [Description("Default Image Prefix")] + public string Default_IMPrefix + { + get { return _Xp["default", "imprefix"]; } + set + { + _Xp["default", "imprefix"] = value; + OnPropertyChanged("RO_IMPrefix"); + } + } + #endregion + #region PrintSettingsCategory // From curset.dat + [Category("Print Settings")] + [DisplayName("Number of Copies")] + [RefreshProperties(RefreshProperties.All)] + [Description("Number of Copies")] + public int Print_NumCopies + { + get + { + string s = _Xp["PrintSettings", "numcopies"]; + if (s == string.Empty) return 1; + return int.Parse(_Xp["PrintSettings", "numcopies"]); + } + set + { + _Xp["PrintSettings", "numcopies"] = value.ToString(); + OnPropertyChanged("Print_NumCopies"); + } + } + public enum PrintPagination : int + { + Free = 0, Fixed, Auto + } + [Category("Print Settings")] + [DisplayName("Pagination")] + [RefreshProperties(RefreshProperties.All)] + [Description("Pagination")] + public PrintPagination Print_Pagination + { + get + { + string s = _Xp["PrintSettings", "Pagination"]; + if (s == string.Empty || s.Equals("-1")) return PrintPagination.Auto; + return (PrintPagination)int.Parse(_Xp["PrintSettings", "Pagination"]); + } + set + { + if (value == PrintPagination.Auto) _Xp["PrintSettings", "Pagination"] = string.Empty; + else _Xp["PrintSettings", "Pagination"] = ((int)value).ToString(); + OnPropertyChanged("Print_Pagination"); + } + } + [TypeConverter(typeof(EnumDescConverter))] + public enum PrintWatermark : int + { + None = 0, Reference, Draft, Master, Sample, + [Description("Information Only")]InformationOnly + } + + [Category("Print Settings")] + [DisplayName("Watermark")] + [RefreshProperties(RefreshProperties.All)] + [Description("Watermark")] + public PrintWatermark Print_Watermark + { + get + { + string s = _Xp["PrintSettings", "Watermark"]; + if (s == string.Empty || s.Equals("-1")) return PrintWatermark.Draft; + return (PrintWatermark)int.Parse(_Xp["PrintSettings", "Watermark"]); + } + set + { + if (value == PrintWatermark.Draft) _Xp["PrintSettings", "Watermark"] = string.Empty; + else _Xp["PrintSettings", "Watermark"] = ((int)value).ToString(); + OnPropertyChanged("Print_Watermark"); + } + } + [Category("Print Settings")] + [DisplayName("Disable Automatic Duplexing")] + //[DisplayName("Disable Duplex Printing")] + [RefreshProperties(RefreshProperties.All)] + [Description("Disable Duplex Printing")] + public bool Print_DisableDuplex + { + get + { + string s = _Xp["PrintSettings", "disableduplex"]; + if (s == string.Empty) return false; + return bool.Parse(_Xp["PrintSettings", "disableduplex"]); + } + set + { + _Xp["PrintSettings", "disableduplex"] = value.ToString(); + OnPropertyChanged("Print_DisableDuplex"); + } + } + // Change Bar Use from 16-bit code: + // No Default + // Without Change Bars + // With Default Change Bars + // With User Specified Change Bars + [TypeConverter(typeof(EnumDescConverter))] + public enum PrintChangeBar : int + { + [Description("Select Before Printing")]SelectBeforePrinting = 0, + [Description("Without Change Bars")]Without, + [Description("With Default Change Bars")]WithDefault, + [Description("Use Custom Change Bars")]WithUserSpecified + } + //{ + // [Description("Select When Printed")]NoDefault = 0, + // [Description("None")]Without, + // [Description("Default")]WithDefault, + // [Description("User Specified")]WithUserSpecified + //} + //[Category("Print Settings")] + [Category("Format Settings")] + [DisplayName("Change Bar")] + [RefreshProperties(RefreshProperties.All)] + [Description("Change Bar Use")] + public PrintChangeBar Print_ChangeBar + { + get + { + string s = _Xp["PrintSettings", "ChangeBar"]; + if (s == string.Empty || s.Equals("-1")) return PrintChangeBar.SelectBeforePrinting;//PrintChangeBar.NoDefault; + return (PrintChangeBar)int.Parse(_Xp["PrintSettings", "ChangeBar"]); + } + set + { + // if (value == PrintChangeBar.NoDefault) _Xp["PrintSettings", "ChangeBar"] = string.Empty; + if (value == PrintChangeBar.SelectBeforePrinting) _Xp["PrintSettings", "ChangeBar"] = string.Empty; + else _Xp["PrintSettings", "ChangeBar"] = ((int)value).ToString(); + OnPropertyChanged("Print_ChangeBar"); + } + } + // User Specified Change Bar Location from16-bit code: + // With Text + // Outside Box + // AER on LEFT, RNO on Right + // To the Left of Text + [TypeConverter(typeof(EnumDescConverter))] + public enum PrintChangeBarLoc : int + { + [Description("With Text")]WithText = 0, + [Description("Outside Box")]OutsideBox, + [Description("AER on Left RNO on Right")]AERleftRNOright, + [Description("To the Left of the Text")]LeftOfText + } + + //[Category("Print Settings")] + [Category("Format Settings")] + //[DisplayName("Change Bar Location")] + [DisplayName("Change Bar Position")] + [RefreshProperties(RefreshProperties.All)] + [Description("User Specified Change Bar Location")] + public PrintChangeBarLoc Print_ChangeBarLoc + { + get + { + string s = _Xp["PrintSettings", "ChangeBarLoc"]; + if (s == string.Empty || s.Equals("-1")) return PrintChangeBarLoc.WithText; + return (PrintChangeBarLoc)int.Parse(_Xp["PrintSettings", "ChangeBarLoc"]); + } + set + { + if (value == PrintChangeBarLoc.WithText) _Xp["PrintSettings", "ChangeBarLoc"] = string.Empty; + else _Xp["PrintSettings", "ChangeBarLoc"] = ((int)value).ToString(); + OnPropertyChanged("Print_ChangeBarLoc"); + } + } + + // Change Bar Text from16-bit code: + // Date and Change ID + // Revision Number + // Change ID + // No Change Bar Message + // User Defined Message + [TypeConverter(typeof(EnumDescConverter))] + public enum PrintChangeBarText : int + { + [Description("Date and Change ID")]DateChgID = 0, + [Description("Revision Number")]RevNum, + [Description("Change ID")]ChgID, + [Description("No Change Bar Text")]None, + [Description("Custom Change Bar Text")]UserDef + } + //[Category("Print Settings")] + [Category("Format Settings")] + //[DisplayName("Change Bar Text")] + [DisplayName("Change bar Text Type")] + [RefreshProperties(RefreshProperties.All)] + [Description("Change Bar Text")] + public PrintChangeBarText Print_ChangeBarText + { + get + { + string s = _Xp["PrintSettings", "ChangeBarText"]; + if (s == string.Empty || s.Equals("-1")) return PrintChangeBarText.DateChgID; + return (PrintChangeBarText)int.Parse(_Xp["PrintSettings", "ChangeBarText"]); + } + set + { + if (value == PrintChangeBarText.DateChgID) _Xp["PrintSettings", "ChangeBarText"] = string.Empty; + else _Xp["PrintSettings", "ChangeBarText"] = ((int)value).ToString(); + OnPropertyChanged("Print_ChangeBarText"); + } + } + + [Category("Print Settings")] + [DisplayName("User Format")] + [RefreshProperties(RefreshProperties.All)] + [Description("User Format")] + public string Print_UserFormat + { + get + { + return _Xp["PrintSettings", "userformat"]; + } + set + { + _Xp["PrintSettings", "userformat"] = value; + OnPropertyChanged("Print_UserFormat"); + } + } + + //[Category("Print Settings")] + [Category("Format Settings")] + //[DisplayName("User Change Bar Message1")] + [DisplayName("Custom Change Bar Message Line One")] + [RefreshProperties(RefreshProperties.All)] + [Description("User Change Bar Message1")] + public string Print_UserCBMess1 + { + get + { + return _Xp["PrintSettings", "usercbmess1"]; + } + set + { + _Xp["PrintSettings", "usercbmess1"] = value; + OnPropertyChanged("Print_UserCBMess1"); + } + } + + //[Category("Print Settings")] + [Category("Format Settings")] + //[DisplayName("User Change Bar Message2")] + [DisplayName("Custom Change Bar Message Line Two")] + [RefreshProperties(RefreshProperties.All)] + [Description("User Change Bar Message2")] + public string Print_UserCBMess2 + { + get + { + return _Xp["PrintSettings", "usercbmess2"]; + } + set + { + _Xp["PrintSettings", "usercbmess2"] = value; + OnPropertyChanged("Print_UserCBMess2"); + } + } + #endregion + //[Category("Defaults")] + [Category("Editor Settings")] + //[DisplayName("Default BackColor")] + [DisplayName("Step Editor Colors - Non Active Background")] + [RefreshProperties(RefreshProperties.All)] + [Description("Default Background Color")] + public Color Default_BkColor + { + get + { + //return _Xp["default", "BkColor"]; + string sColor = _Xp["default", "BkColor"]; + if (sColor == string.Empty) sColor = "White"; + if (sColor[0] == '[') + { + string[] parts = sColor.Substring(1, sColor.Length - 2).Split(",".ToCharArray()); + return Color.FromArgb(Int32.Parse(parts[0]), Int32.Parse(parts[1]), Int32.Parse(parts[2])); + } + else return Color.FromName(sColor); + } + set + { + if (value.IsNamedColor) _Xp["default", "BkColor"] = value.Name; + else + { + _Xp["default", "BkColor"] = string.Format("[{0},{1},{2}]", value.R, value.G, value.B); + } + OnPropertyChanged("Default_BkColor"); + } + } + } +} diff --git a/PROMS/VEPROMS.CSLA.Library/Config/ProcConfig.cs b/PROMS/VEPROMS.CSLA.Library/Config/ProcConfig.cs new file mode 100644 index 00000000..5185c38c --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Config/ProcConfig.cs @@ -0,0 +1,520 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.ComponentModel; +using DescriptiveEnum; + +namespace VEPROMS.CSLA.Library +{ + [Serializable] + [TypeConverter(typeof(ExpandableObjectConverter))] + public class ProcedureConfig : DynamicTypeDescriptor, INotifyPropertyChanged + { + #region Events + public event PropertyChangedEventHandler PropertyChanged; + private void OnPropertyChanged(String info) + { + if (PropertyChanged != null) + PropertyChanged(this, new PropertyChangedEventArgs(info)); + } + #endregion + #region DynamicTypeDescriptor + internal override bool IsReadOnly + { + get { return _Procedure == null; } + } + #endregion + #region XML + private XMLProperties _Xp; + private XMLProperties Xp + { + get { return _Xp; } + } + #endregion + #region Constructors + public bool ParentLookup + { + get { return _Xp.ParentLookup; } + set { _Xp.ParentLookup = value; } + } + [NonSerialized] + private bool _AncestorLookup; + public bool AncestorLookup + { + get { return _AncestorLookup; } + set { _AncestorLookup = value; } + } + private Procedure _Procedure; + private ProcedureInfo _ProcedureInfo; + public ProcedureConfig(Procedure procedure) + { + _Procedure = procedure; + string xml = procedure.MyContent.Config; + if (xml == string.Empty) xml = ""; + _Xp = new XMLProperties(xml); + if (procedure.ActiveParent != null) _Xp.LookInAncestor += new XMLPropertiesEvent(Xp_LookInAncestorFolder); + } + private string Xp_LookInAncestorFolder(object sender, XMLPropertiesArgs args) + { + if (_AncestorLookup || ParentLookup) + { + string retval; + Procedure proc = _Procedure; + while (proc.ActiveParent.GetType() == typeof(Procedure)) + { + retval = proc.ProcedureConfig.GetValue(args.Group, args.Item); + if (retval != string.Empty) return retval; + proc = (Procedure) proc.ActiveParent; + } + DocVersion docVersion = (DocVersion)proc.ActiveParent; + retval = docVersion.DocVersionConfig.GetValue(args.Group, args.Item); + if (retval != string.Empty) return retval; + for (Folder folder = docVersion.MyFolder; folder != null; folder = folder.MyParent) + { + retval = folder.FolderConfig.GetValue(args.Group, args.Item); + if (retval != string.Empty) return retval; + } + } + return string.Empty; + } + private string Xp_LookInAncestorFolderInfo(object sender, XMLPropertiesArgs args) + { + if (_AncestorLookup || ParentLookup) + { + + DocVersionInfo docVersion = (DocVersionInfo)_Procedure.ActiveParent; + string retval = docVersion.DocVersionConfig.GetValue(args.Group, args.Item); + if (retval != string.Empty) return retval; + for (FolderInfo folder = docVersion.MyFolder; folder != null; folder = folder.MyParent) + { + retval = folder.FolderConfig.GetValue(args.Group, args.Item); + if (retval != string.Empty) return retval; + } + } + return string.Empty; + } + public ProcedureConfig(ProcedureInfo procedureInfo) + { + _ProcedureInfo = procedureInfo; + string xml = procedureInfo.MyContent.Config; + if (xml == string.Empty) xml = ""; + _Xp = new XMLProperties(xml); + } + public ProcedureConfig(string xml) + { + if (xml == string.Empty) xml = ""; + _Xp = new XMLProperties(xml); + } + //public ProcedureConfig() + //{ + // _Xp = new XMLProperties(); + //} + internal string GetValue(string group, string item) + { + return _Xp[group, item]; + } + #endregion + #region Local Properties + //[Category("Identification")] + [Category("General")] + [DisplayName("Number")] + [Description("Number")] + public string Number + { + get { return (_Procedure != null ? _Procedure.MyContent.Number : _ProcedureInfo.MyContent.Number); } + set { if (_Procedure != null) _Procedure.MyContent.Number = value; } + } + //[Category("Identification")] + [Category("General")] + [DisplayName("Title")] + [Description("Title")] + public string Title + { + get { return (_Procedure != null ? _Procedure.MyContent.Text : _ProcedureInfo.MyContent.Text); } + set { if (_Procedure != null) _Procedure.MyContent.Text = value; } + } + [Category("Identification")] + [DisplayName("Old Sequence")] + [Description("Old Sequence")] + public string OldSequence + { + get { return (_Procedure != null ? _Procedure.MyContent.MyZContent.OldStepSequence : (_ProcedureInfo.MyContent.MyZContent == null? null :_ProcedureInfo.MyContent.MyZContent.OldStepSequence)); } + set { if (_Procedure != null) _Procedure.MyContent.MyZContent.OldStepSequence = value; } + } + [Category("Identification")] + [DisplayName("Dirty")] + [Description("Dirty")] + public bool Dirty + { + get { return (_Procedure != null ? _Procedure.IsDirty : false ); } + } + //[Category("Format")] + [Category("Format Settings")] + [DisplayName("Format")] + [Description("Format")] + [TypeConverter(typeof(FormatList))] + public string FormatSelection + { + get + { + //if (_DocVersion != null) return FormatList.ToString(_DocVersion.FormatID); + //if (_DocVersionInfo != null) return FormatList.ToString(_DocVersionInfo.FormatID); + if (_Procedure != null && _Procedure.MyContent.MyFormat != null) return _Procedure.MyContent.MyFormat.PlantFormat.FormatData.Name; + if (_ProcedureInfo != null && _ProcedureInfo.MyContent.MyFormat != null) return _ProcedureInfo.MyContent.MyFormat.PlantFormat.FormatData.Name; + return null; + } + set + { + if (_Procedure != null) _Procedure.MyContent.MyFormat = FormatList.ToFormat(value); // Can only be set if _DocVersion is set + } + } + //[Category("Format")] + [Category("Format Settings")] + //[DisplayName("Format")] + [DisplayName("Default Format")] + [Description("Format")] + [TypeConverter(typeof(FormatList))] + public string DefaultFormatSelection + { + get + { + //if (_Folder != null) return FormatList.ToString(_Folder.FormatID); + //if (_FolderInfo != null) return FormatList.ToString(_FolderInfo.FormatID); + if (_Procedure != null && _Procedure.ActiveParent != null && _Procedure.ActiveParent.ActiveFormat != null) return _Procedure.ActiveParent.ActiveFormat.PlantFormat.FormatData.Name; + if (_ProcedureInfo != null && _ProcedureInfo.MyParent != null && _ProcedureInfo.MyParent.ActiveFormat != null) return _ProcedureInfo.MyParent.ActiveFormat.PlantFormat.FormatData.Name; + return null; + } + } + #endregion + #region ToString + public override string ToString() + { + string s = _Xp.ToString(); + if (s == "" || s == "") return string.Empty; + return s; + } + #endregion + #region FormatCategory + [TypeConverter(typeof(EnumDescConverter))] + public enum FormatColumns : int + { + Default = 0, + [Description("Single Column")] + OneColumn, + [Description("Duel Column")] + TwoColumn, + [Description("Triple Column")] + ThreeColumn, + [Description("Quad Column")] + FourColumns + } + //[Category("Format")] + [Category("General")] + //[DisplayName("Column Layout")] + [DisplayName("Default Column Mode")] + [RefreshProperties(RefreshProperties.All)] + [Description("Column Layout")] + public FormatColumns Format_Columns + { + get + { + string s = _Xp["format", "columns"]; + if (s == string.Empty || s.Equals("-1")) return FormatColumns.Default;//(FormatColumns)0; + return (FormatColumns)int.Parse(_Xp["format", "columns"]); + //return Enum.Parse(typeof(FormatColumns),_Xp["format", "columns"]); + } + set + { + if (value == 0) _Xp["format", "columns"] = string.Empty; + else _Xp["format", "columns"] = ((int)value).ToString(); + OnPropertyChanged("Format_Columns"); + } + } + [Category("Format")] + [DisplayName("Plant Format Name")] + [RefreshProperties(RefreshProperties.All)] + [Description("Default Plant Format")] + public string Format_Plant + { + get + { + return _Xp["format", "plant"]; + } + set + { + _Xp["format", "plant"] = value; + OnPropertyChanged("Format_Plant"); + } + } + #endregion + #region PrintSettingsCategory // From curset.dat + [Category("Print Settings")] + [DisplayName("Number of Copies")] + [RefreshProperties(RefreshProperties.All)] + [Description("Number of Copies")] + public int Print_NumCopies + { + get + { + string s = _Xp["PrintSettings", "numcopies"]; + if (s == string.Empty) return 1; + return int.Parse(_Xp["PrintSettings", "numcopies"]); + } + set + { + _Xp["PrintSettings", "numcopies"] = value.ToString(); + OnPropertyChanged("Print_NumCopies"); + } + } + public enum PrintPagination : int + { + Free = 0, Fixed, + [Description("Automatic")] + Auto + } + [Category("Print Settings")] + [DisplayName("Pagination")] + [RefreshProperties(RefreshProperties.All)] + [Description("Pagination")] + public PrintPagination Print_Pagination + { + get + { + string s = _Xp["PrintSettings", "Pagination"]; + if (s == string.Empty || s.Equals("-1")) return PrintPagination.Auto; + return (PrintPagination)int.Parse(_Xp["PrintSettings", "Pagination"]); + } + set + { + if (value == PrintPagination.Auto) _Xp["PrintSettings", "Pagination"] = string.Empty; + else _Xp["PrintSettings", "Pagination"] = ((int)value).ToString(); + OnPropertyChanged("Print_Pagination"); + } + } + [TypeConverter(typeof(EnumDescConverter))] + public enum PrintWatermark : int + { + None = 0, Reference, Draft, Master, Sample, + [Description("Information Only")] + InformationOnly + } + [Category("Print Settings")] + [DisplayName("Watermark")] + [RefreshProperties(RefreshProperties.All)] + [Description("Watermark")] + public PrintWatermark Print_Watermark + { + get + { + string s = _Xp["PrintSettings", "Watermark"]; + if (s == string.Empty || s.Equals("-1")) return PrintWatermark.Draft; + return (PrintWatermark)int.Parse(_Xp["PrintSettings", "Watermark"]); + } + set + { + if (value == PrintWatermark.Draft) _Xp["PrintSettings", "Watermark"] = string.Empty; + else _Xp["PrintSettings", "Watermark"] = ((int)value).ToString(); + OnPropertyChanged("Print_Watermark"); + } + } + [Category("Print Settings")] + //[DisplayName("Disable Duplex Printing")] + [DisplayName("Disable Automatic Duplexing")] + [RefreshProperties(RefreshProperties.All)] + [Description("Disable Duplex Printing")] + public bool Print_DisableDuplex + { + get + { + string s = _Xp["PrintSettings", "disableduplex"]; + if (s == string.Empty) return false; + return bool.Parse(_Xp["PrintSettings", "disableduplex"]); + } + set + { + _Xp["PrintSettings", "disableduplex"] = value.ToString(); + OnPropertyChanged("Print_DisableDuplex"); + } + } + // Change Bar Use from 16-bit code: + // No Default + // Without Change Bars + // With Default Change Bars + // With User Specified Change Bars + [TypeConverter(typeof(EnumDescConverter))] + public enum PrintChangeBar : int + { + [Description("Select Before Printing")] + SelectBeforePrinting = 0, + [Description("Without Change Bars")] + Without, + [Description("With Default Change Bars")] + WithDefault, + [Description("Use Custom Change Bars")] + WithUserSpecified + } + //{ + // [Description("Select When Printed")]NoDefault = 0, + // [Description("None")]Without, + // [Description("Default")]WithDefault, + // [Description("User Specified")]WithUserSpecified + //} + //[Category("Print Settings")] + [Category("Format Settings")] + [DisplayName("Change Bar")] + [RefreshProperties(RefreshProperties.All)] + [Description("Change Bar Use")] + public PrintChangeBar Print_ChangeBar + { + get + { + string s = _Xp["PrintSettings", "ChangeBar"]; + if (s == string.Empty || s.Equals("-1")) return PrintChangeBar.SelectBeforePrinting;//PrintChangeBar.NoDefault; + return (PrintChangeBar)int.Parse(_Xp["PrintSettings", "ChangeBar"]); + } + set + { + //if (value == PrintChangeBar.NoDefault) _Xp["PrintSettings", "ChangeBar"] = string.Empty; + if (value == PrintChangeBar.SelectBeforePrinting) _Xp["PrintSettings", "ChangeBar"] = string.Empty; + else _Xp["PrintSettings", "ChangeBar"] = ((int)value).ToString(); + OnPropertyChanged("Print_ChangeBar"); + } + } + // User Specified Change Bar Location from16-bit code: + // With Text + // Outside Box + // AER on LEFT, RNO on Right + // To the Left of Text + [TypeConverter(typeof(EnumDescConverter))] + public enum PrintChangeBarLoc : int + { + [Description("With Text")] + WithText = 0, + [Description("Outside Box")] + OutsideBox, + [Description("AER on Left RNO on Right")] + AERleftRNOright, + [Description("To the Left of the Text")] + LeftOfText + } + //[Category("Print Settings")] + [Category("Format Settings")] + //[DisplayName("Change Bar Location")] + [DisplayName("Change Bar Position")] + [RefreshProperties(RefreshProperties.All)] + [Description("User Specified Change Bar Location")] + public PrintChangeBarLoc Print_ChangeBarLoc + { + get + { + string s = _Xp["PrintSettings", "ChangeBarLoc"]; + if (s == string.Empty || s.Equals("-1")) return PrintChangeBarLoc.WithText; + return (PrintChangeBarLoc)int.Parse(_Xp["PrintSettings", "ChangeBarLoc"]); + } + set + { + if (value == PrintChangeBarLoc.WithText) _Xp["PrintSettings", "ChangeBarLoc"] = string.Empty; + else _Xp["PrintSettings", "ChangeBarLoc"] = ((int)value).ToString(); + OnPropertyChanged("Print_ChangeBarLoc"); + } + } + + // Change Bar Text from16-bit code: + // Date and Change ID + // Revision Number + // Change ID + // No Change Bar Message + // User Defined Message + [TypeConverter(typeof(EnumDescConverter))] + public enum PrintChangeBarText : int + { + [Description("Date and Change ID")] + DateChgID = 0, + [Description("Revision Number")] + RevNum, + [Description("Change ID")] + ChgID, + [Description("No Change Bar Text")] + None, + [Description("Custom Change Bar Text")] + UserDef + } + //[Category("Print Settings")] + [Category("Format Settings")] + //[DisplayName("Change Bar Text")] + [DisplayName("Change Bar Text Type")] + [RefreshProperties(RefreshProperties.All)] + [Description("Change Bar Text")] + public PrintChangeBarText Print_ChangeBarText + { + get + { + string s = _Xp["PrintSettings", "ChangeBarText"]; + if (s == string.Empty || s.Equals("-1")) return PrintChangeBarText.DateChgID; + return (PrintChangeBarText)int.Parse(_Xp["PrintSettings", "ChangeBarText"]); + } + set + { + if (value == PrintChangeBarText.DateChgID) _Xp["PrintSettings", "ChangeBarText"] = string.Empty; + else _Xp["PrintSettings", "ChangeBarText"] = ((int)value).ToString(); + OnPropertyChanged("Print_ChangeBarText"); + } + } + + [Category("Print Settings")] + [DisplayName("User Format")] + [RefreshProperties(RefreshProperties.All)] + [Description("User Format")] + public string Print_UserFormat + { + get + { + return _Xp["PrintSettings", "userformat"]; + } + set + { + _Xp["PrintSettings", "userformat"] = value; + OnPropertyChanged("Print_UserFormat"); + } + } + + //[Category("Print Settings")] + [Category("Format Settings")] + //[DisplayName("User Change Bar Message1")] + [DisplayName("Custom Change Bar Message Line One")] + [RefreshProperties(RefreshProperties.All)] + [Description("User Change Bar Message1")] + public string Print_UserCBMess1 + { + get + { + return _Xp["PrintSettings", "usercbmess1"]; + } + set + { + _Xp["PrintSettings", "usercbmess1"] = value; + OnPropertyChanged("Print_UserCBMess1"); + } + } + + //[Category("Print Settings")] + [Category("Format Settings")] + //[DisplayName("User Change Bar Message2")] + [DisplayName("Custom Change Bar Message Line Two")] + [RefreshProperties(RefreshProperties.All)] + [Description("User Change Bar Message2")] + public string Print_UserCBMess2 + { + get + { + return _Xp["PrintSettings", "usercbmess2"]; + } + set + { + _Xp["PrintSettings", "usercbmess2"] = value; + OnPropertyChanged("Print_UserCBMess2"); + } + } + #endregion + } +} diff --git a/PROMS/VEPROMS.CSLA.Library/Config/SectionConfig.cs b/PROMS/VEPROMS.CSLA.Library/Config/SectionConfig.cs new file mode 100644 index 00000000..753b40db --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Config/SectionConfig.cs @@ -0,0 +1,441 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.ComponentModel; +using DescriptiveEnum; + +namespace VEPROMS.CSLA.Library +{ + [Serializable] + [TypeConverter(typeof(ExpandableObjectConverter))] + public class SectionConfig : DynamicTypeDescriptor, INotifyPropertyChanged + { + #region Events + public event PropertyChangedEventHandler PropertyChanged; + private void OnPropertyChanged(String info) + { + if (PropertyChanged != null) + PropertyChanged(this, new PropertyChangedEventArgs(info)); + } + #endregion + #region DynamicTypeDescriptor + internal override bool IsReadOnly + { + get { return false; }//_Section == null; } + } + #endregion + #region XML + private XMLProperties _Xp; + private XMLProperties Xp + { + get { return _Xp; } + } + #endregion + #region Constructors + public bool ParentLookup + { + get { return _Xp.ParentLookup; } + set { _Xp.ParentLookup = value; } + } + [NonSerialized] + private bool _AncestorLookup; + public bool AncestorLookup + { + get { return _AncestorLookup; } + set { _AncestorLookup = value; } + } + private Section _Section; + private SectionInfo _SectionInfo; + public SectionConfig(Section section) + { + _Section = section; + string xml = section.MyContent.Config; + if (xml == string.Empty) xml = ""; + _Xp = new XMLProperties(xml); + if (section.ActiveParent != null) _Xp.LookInAncestor += new XMLPropertiesEvent(Xp_LookInAncestorFolder); + } + private string Xp_LookInAncestorFolder(object sender, XMLPropertiesArgs args) + { + if (_AncestorLookup || ParentLookup) + { + string retval; + Section sect = _Section; + while (sect.ActiveParent.GetType() == typeof(Section)) + { + retval = sect.SectionConfig.GetValue(args.Group, args.Item); + if (retval != string.Empty) return retval; + sect = (Section)sect.ActiveParent; + } + Procedure proc = (Procedure) sect.ActiveParent; + while (proc.ActiveParent.GetType() == typeof(Procedure)) + { + retval = proc.ProcedureConfig.GetValue(args.Group, args.Item); + if (retval != string.Empty) return retval; + proc = (Procedure)proc.ActiveParent; + } + DocVersion docVersion = (DocVersion)proc.ActiveParent; + retval = docVersion.DocVersionConfig.GetValue(args.Group, args.Item); + if (retval != string.Empty) return retval; + for (Folder folder = docVersion.MyFolder; folder != null; folder = folder.MyParent) + { + retval = folder.FolderConfig.GetValue(args.Group, args.Item); + if (retval != string.Empty) return retval; + } + } + return string.Empty; + } + private string Xp_LookInAncestorFolderInfo(object sender, XMLPropertiesArgs args) + { + if (_AncestorLookup || ParentLookup) + { + string retval; + Section sect = _Section; + while (sect.ActiveParent.GetType() == typeof(Section)) + { + //retval = sect.SectionConfig.GetValue(args.Group, args.Item); + //if (retval != string.Empty) return retval; + sect = (Section)sect.ActiveParent; + } + Procedure proc = (Procedure)sect.ActiveParent; + DocVersionInfo docVersion = (DocVersionInfo) proc.ActiveParent; + retval = docVersion.DocVersionConfig.GetValue(args.Group, args.Item); + if (retval != string.Empty) return retval; + for (FolderInfo folder = docVersion.MyFolder; folder != null; folder = folder.MyParent) + { + retval = folder.FolderConfig.GetValue(args.Group, args.Item); + if (retval != string.Empty) return retval; + } + } + return string.Empty; + } + public SectionConfig(SectionInfo sectionInfo) + { + _SectionInfo = sectionInfo; + string xml = sectionInfo.MyContent.Config; + if (xml == string.Empty) xml = ""; + _Xp = new XMLProperties(xml); + } + public SectionConfig(string xml) + { + if (xml == string.Empty) xml = ""; + _Xp = new XMLProperties(xml); + } + public SectionConfig() + { + _Xp = new XMLProperties(); + } + internal string GetValue(string group, string item) + { + return _Xp[group, item]; + } + #endregion + #region Local Properties + //[Category("Identification")] + [Category("General")] + [DisplayName("Number")] + [Description("Number")] + public string Number + { + get { return (_Section != null ? _Section.MyContent.Number : _SectionInfo.MyContent.Number); } + set { if (_Section != null) _Section.MyContent.Number = value; } + } + //[Category("Identification")] + [Category("General")] + [DisplayName("Title")] + [Description("Title")] + public string Title + { + get { return (_Section != null ? _Section.MyContent.Text : _SectionInfo.MyContent.Text); } + set { if (_Section != null) _Section.MyContent.Text = value; } + } + [Category("Identification")] + [DisplayName("Old Sequence")] + [Description("Old Sequence")] + public string OldSequence + { + get { return (_Section != null ? _Section.MyContent.MyZContent.OldStepSequence : (_SectionInfo.MyContent.MyZContent == null ? null : _SectionInfo.MyContent.MyZContent.OldStepSequence)); } + set { if (_Section != null) _Section.MyContent.MyZContent.OldStepSequence = value; } + } + [Category("Identification")] + [DisplayName("Dirty")] + [Description("Dirty")] + public bool Dirty + { + get { return (_Section != null ? _Section.IsDirty : false); } + } + [Category("Format")] + [DisplayName("Format")] + [Description("Format")] + [TypeConverter(typeof(FormatList))] + public string FormatSelection + { + get + { + //if (_DocVersion != null) return FormatList.ToString(_DocVersion.FormatID); + //if (_DocVersionInfo != null) return FormatList.ToString(_DocVersionInfo.FormatID); + if (_Section != null && _Section.MyContent.MyFormat != null) return _Section.MyContent.MyFormat.PlantFormat.FormatData.Name; + if (_SectionInfo != null && _SectionInfo.MyContent.MyFormat != null) return _SectionInfo.MyContent.MyFormat.PlantFormat.FormatData.Name; + return null; + } + set + { + if (_Section != null) _Section.MyContent.MyFormat = FormatList.ToFormat(value); // Can only be set if _DocVersion is set + } + } + [Category("Format")] + //[DisplayName("DefFormat")] + [DisplayName("Default Format")] + [Description("Format")] + [TypeConverter(typeof(FormatList))] + public string DefaultFormatSelection + { + get + { + //if (_Folder != null) return FormatList.ToString(_Folder.FormatID); + //if (_FolderInfo != null) return FormatList.ToString(_FolderInfo.FormatID); + if (_Section != null && _Section.ActiveParent != null && _Section.ActiveParent.ActiveFormat != null) return _Section.ActiveParent.ActiveFormat.PlantFormat.FormatData.Name; + if (_SectionInfo != null && _SectionInfo.MyParent != null && _SectionInfo.MyParent.ActiveFormat != null) return _SectionInfo.MyParent.ActiveFormat.PlantFormat.FormatData.Name; + return null; + } + } + #endregion + #region ToString + public override string ToString() + { + string s = _Xp.ToString(); + if (s == "" || s == "") return string.Empty; + return s; + } + #endregion + #region SectionCategory // from sequence number in 16-bit database. + // jsj ... + public enum SectionPagination : int + { + Default = 0, Continuous, Separate + } + //[Category("Section")] + [Category("Format")] + [DisplayName("Section Pagination")] + [RefreshProperties(RefreshProperties.All)] + [Description("Section Pagination")] + public SectionPagination Section_Pagination + { + get + { + string s = _Xp["Section", "Pagination"]; + if (s == string.Empty || s.Equals("-1")) return SectionPagination.Default; + return (SectionPagination)int.Parse(_Xp["Section", "Pagination"]); + } + set + { + if (value == SectionPagination.Default) _Xp["Section", "Pagination"] = string.Empty; + else _Xp["Section", "Pagination"] = ((int)value).ToString(); + OnPropertyChanged("Section_Pagination"); + } + } + // ... jsj + + //[Category("Section")] + //[DisplayName("Section Pagination")] + //[RefreshProperties(RefreshProperties.All)] + //[Description("Section Pagination")] + //public string Section_Pagination + //{ + // get + // { + // return _Xp["Section", "Pagination"]; + // } + // set + // { + // _Xp["Section", "Pagination"] = value; + // OnPropertyChanged("Section_Pagination"); + // } + //} + //[Category("Section")] + [Category("View Settings")] + //[DisplayName("Section LinkEnhanced")] + [DisplayName("Include in Background/Deviation")] + [RefreshProperties(RefreshProperties.All)] + [Description("Section LinkEnhanced")] + public string Section_LnkEnh + { + get + { + return _Xp["Section", "LnkEnh"]; + } + set + { + _Xp["Section", "LnkEnh"] = value; + OnPropertyChanged("Section_LnkEnh"); + } + } + //[Category("Section")] + [Category("General")] + //[DisplayName("Section TOC")] + [DisplayName("Include On Table Of Contents")] + [RefreshProperties(RefreshProperties.All)] + [Description("Section TOC")] + public string Section_TOC + { + get + { + return _Xp["Section", "TOC"]; + } + set + { + _Xp["Section", "TOC"] = value; + OnPropertyChanged("Section_TOC"); + } + } + [Category("Section")] + [DisplayName("Section AutoGen")] + [RefreshProperties(RefreshProperties.All)] + [Description("Section AutoGen")] + public string Section_AutoGen + { + get + { + return _Xp["Section", "AutoGen"]; + } + set + { + _Xp["Section", "AutoGen"] = value; + OnPropertyChanged("Section_AutoGen"); + } + } + [Category("Section")] + [DisplayName("Section NumPages")] + [RefreshProperties(RefreshProperties.All)] + [Description("Section NumPages")] + public string Section_NumPages + { + get + { + return _Xp["Section", "NumPages"]; + } + set + { + _Xp["Section", "NumPages"] = value; + OnPropertyChanged("Section_NumPages"); + } + } + // jsj ... + [TypeConverter(typeof(EnumDescConverter))] + public enum SectionColumnMode : int + { + Default = 0, + [Description("Single Column")]One, + [Description("Duel Column")]Two, + [Description("Triple Column")]Three, + [Description("Quad Column")]Four + } + //[Category("Section")] + [Category("Format")] + //[DisplayName("Section ColumnMode")] + [DisplayName("Columns")] + [RefreshProperties(RefreshProperties.All)] + [Description("Section ColumnMode")] + public SectionColumnMode Section_ColumnMode + { + get + { + string s = _Xp["Section", "ColumnMode"]; + if (s == string.Empty || s.Equals("-1")) return SectionColumnMode.Default; + return (SectionColumnMode)int.Parse(_Xp["Section", "ColumnMode"]); + } + set + { + if (value == SectionColumnMode.Default) _Xp["Section", "ColumnMode"] = string.Empty; + else _Xp["Section", "ColumnMode"] = ((int)value).ToString(); + OnPropertyChanged("Section_ColumnMode"); + } + } + // ... jsj + + //[Category("Section")] + //[DisplayName("Section ColumnMode")] + //[RefreshProperties(RefreshProperties.All)] + //[Description("Section ColumnMode")] + //public string Section_ColumnMode + //{ + // get + // { + // return _Xp["Section", "ColumnMode"]; + // } + // set + // { + // _Xp["Section", "ColumnMode"] = value; + // OnPropertyChanged("Section_ColumnMode"); + // } + //} + #endregion + #region SubSectionCategory // from sequence number in 16-bit database. + [Category("SubSection")] + [DisplayName("SubSection Edit")] + [RefreshProperties(RefreshProperties.All)] + [Description("SubSection Edit")] + public string SubSection_Edit + { + get + { + return _Xp["SubSection", "Edit"]; + } + set + { + _Xp["SubSection", "Edit"] = value; + OnPropertyChanged("SubSection_Edit"); + } + } + [Category("SubSection")] + [DisplayName("SubSection PH")] + [RefreshProperties(RefreshProperties.All)] + [Description("SubSection PH")] + public string SubSection_PH + { + get + { + return _Xp["SubSection", "PH"]; + } + set + { + _Xp["SubSection", "PH"] = value; + OnPropertyChanged("SubSection_PH"); + } + } + [Category("SubSection")] + [DisplayName("SubSection AutoIndent")] + [RefreshProperties(RefreshProperties.All)] + [Description("SubSection AutoIndent")] + public string SubSection_AutoIndent + { + get + { + return _Xp["SubSection", "AutoIndent"]; + } + set + { + _Xp["SubSection", "AutoIndent"] = value; + OnPropertyChanged("SubSection_AutoIndent"); + } + } + #endregion + #region LibDocCategory // from library document file during migration + [Category("LibraryDocument")] + [DisplayName("LibraryDocument Comment")] + [RefreshProperties(RefreshProperties.All)] + [Description("LibraryDocument Comment")] + public string LibDoc_Comment + { + get + { + return _Xp["LibraryDocument", "Comment"]; + } + set + { + _Xp["LibraryDocument", "Comment"] = value; + OnPropertyChanged("LibDoc_Comment"); + } + } + #endregion + } +} diff --git a/PROMS/VEPROMS.CSLA.Library/Config/UserConfig.cs b/PROMS/VEPROMS.CSLA.Library/Config/UserConfig.cs new file mode 100644 index 00000000..cd4013ff --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Config/UserConfig.cs @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.ComponentModel; + +namespace VEPROMS.CSLA.Library +{ + [Serializable] + [TypeConverter(typeof(ExpandableObjectConverter))] + public class UserConfig:INotifyPropertyChanged + { + public event PropertyChangedEventHandler PropertyChanged; + private void OnPropertyChanged(String info) + { + if (PropertyChanged != null) + PropertyChanged(this, new PropertyChangedEventArgs(info)); + } + private XMLProperties _Xp; + private XMLProperties Xp + { + get { return _Xp; } + } + public UserConfig(string xml) + { + if (xml == string.Empty) xml = ""; + _Xp = new XMLProperties(xml); + } + public UserConfig() + { + _Xp = new XMLProperties(); + } + public override string ToString() + { + string s = _Xp.ToString(); + if (s == "" || s == "") return string.Empty; + return s; + } + #region UserCategory // from user.cfg + [Category("User")] + [DisplayName("User Location1")] + [RefreshProperties(RefreshProperties.All)] + [Description("User Location1")] + public string User_UserLoc1 + { + get + { + return _Xp["user", "UserLoc1"]; + } + set + { + _Xp["user", "UserLoc1"] = value; + OnPropertyChanged("User_UserLoc1"); + } + } + [Category("User")] + [DisplayName("User Location2")] + [RefreshProperties(RefreshProperties.All)] + [Description("User Location2")] + public string User_UserLoc2 + { + get + { + return _Xp["user", "UserLoc2"]; + } + set + { + _Xp["user", "UserLoc2"] = value; + OnPropertyChanged("User_UserLoc2"); + } + } + [Category("User")] + [DisplayName("User Phone1")] + [RefreshProperties(RefreshProperties.All)] + [Description("User Phone1")] + public string User_UserPhone1 + { + get + { + return _Xp["user", "UserPhone1"]; + } + set + { + _Xp["user", "UserPhone1"] = value; + OnPropertyChanged("User_UserPhone1"); + } + } + [Category("User")] + [DisplayName("User Phone2")] + [RefreshProperties(RefreshProperties.All)] + [Description("User Phone2")] + public string User_UserPhone2 + { + get + { + return _Xp["user", "UserPhone2"]; + } + set + { + _Xp["user", "UserPhone2"] = value; + OnPropertyChanged("User_UserPhone2"); + } + } + #endregion + } +} diff --git a/PROMS/VEPROMS.CSLA.Library/Config/XMLProperties.cs b/PROMS/VEPROMS.CSLA.Library/Config/XMLProperties.cs new file mode 100644 index 00000000..fd473b55 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Config/XMLProperties.cs @@ -0,0 +1,171 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.Serialization; +using System.Xml; + +namespace VEPROMS.CSLA.Library +{ + public delegate string XMLPropertiesEvent(object sender, XMLPropertiesArgs args); + [Serializable()] + public class XMLProperties + { + #region Events + public event XMLPropertiesEvent LookInAncestor; + private string OnLookInAncestor(object sender, XMLPropertiesArgs args) + { + if (LookInAncestor != null) return LookInAncestor(sender, args); + return string.Empty; + } + #endregion + #region Constructors + public XMLProperties() + { + _XmlContents = new XmlDocument(); + _XmlContents.LoadXml(""); + } + public XMLProperties(string xml) + { + _XmlContents = new XmlDocument(); + _XmlContents.LoadXml(xml); + } + #endregion + #region BusinessMethods + [NonSerialized] + private bool _ParentLookup=false; + public bool ParentLookup + { + get { return _ParentLookup; } + set { _ParentLookup = value; } + } + [NonSerialized] + XmlDocument _XmlContents; + public XmlDocument XmlContents + { + get { return _XmlContents; } + } + private XmlNode GetGroup(string group) + { + XmlNodeList xl = _XmlContents.DocumentElement.SelectNodes(string.Format("//{0}", group)); + switch (xl.Count) + { + case 0: // No nodes found + return null; + case 1: // Found the node + XmlNode xn = xl[0]; + if (xn.GetType() == typeof(XmlElement)) return xn; + throw new XmlPropertiesException("Retrieved {0} while looking for XmlElement //{1}", xn.GetType().ToString(), group); + default: // Found more than 1 node + throw new XmlPropertiesException("Found more than one node //{0}", group); + } + } + private XmlAttribute GetItem(XmlNode xx, string item) + { + XmlNodeList xl = xx.SelectNodes(string.Format("@{0}", item)); + switch (xl.Count) + { + case 0: // No nodes found + return null; + case 1: // Found the node + XmlNode xn = xl[0]; + if (xn.GetType() == typeof(XmlAttribute)) return (XmlAttribute)xn; + throw new XmlPropertiesException("Retrieved {0} while looking for XmlAttribute @{1}", xn.GetType().ToString(), item); + default: // Found more than 1 node + throw new XmlPropertiesException("Found more than one node @{0}", item); + } + } + public string this[string group, string item] + { + get + { + if (_ParentLookup) + return OnLookInAncestor(this, new XMLPropertiesArgs(group, item)); + XmlNode xn = GetGroup(group); + if (xn == null) return OnLookInAncestor(this,new XMLPropertiesArgs(group,item)); + XmlNode xa = GetItem(xn, item); + if (xa == null) return OnLookInAncestor(this, new XMLPropertiesArgs(group, item)); + return xa.InnerText; + } + set + { + if (value == null) value = string.Empty; + XmlNode xn = GetGroup(group); + if (xn == null) + { + if (value != string.Empty)// Add Group and Item + { + xn = _XmlContents.DocumentElement.AppendChild(_XmlContents.CreateElement(group)); + XmlAttribute xa = xn.Attributes.Append(_XmlContents.CreateAttribute(item)); + xa.Value = value; + } + } + else + { + XmlAttribute xa = GetItem(xn, item); + if (xa == null) + { + if (value != string.Empty) // Add Item + { + xa = xn.Attributes.Append(_XmlContents.CreateAttribute(item)); + xa.Value = value; + } + } + else + { + if (value != string.Empty) // Add Item + { + xa.Value = value; + } + else + { + xn.Attributes.Remove(xa); + if (xn.Attributes.Count == 0) + _XmlContents.DocumentElement.RemoveChild(xn); + } + } + } + } + } + public override string ToString() + { + if (XmlContents == null) return null; + return XmlContents.OuterXml; + } + #endregion + #region XmlPropertiesException + public class XmlPropertiesException : Exception + { + public XmlPropertiesException() : base() { ;} + public XmlPropertiesException(string message) : base(message) { ;} + public XmlPropertiesException(string messageFormat,params object [] args) : base(string.Format(messageFormat,args)) { ;} + public XmlPropertiesException(SerializationInfo info, StreamingContext context) : base(info, context) { ;} + public XmlPropertiesException(string message,Exception innerException) : base(message, innerException) { ;} + } + #endregion + } + public partial class XMLPropertiesArgs + { + #region Business Methods + private string _Group; + public string Group + { + get { return _Group; } + set { _Group = value; } + } + private string _Item; + public string Item + { + get { return _Item; } + set { _Item = value; } + } + #endregion + #region Factory Methods + private XMLPropertiesArgs() { ;} + public XMLPropertiesArgs(string group, string item) + { + _Group=group; + _Item=item; + } + #endregion + } +} diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/AnnotationExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/AnnotationExt.cs new file mode 100644 index 00000000..8b1fd74b --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Extension/AnnotationExt.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace VEPROMS.CSLA.Library +{ + public partial class AnnotationInfo + { + public override string ToString() + { + return _SearchText; + } + } + + public partial class AnnotationType + { + public override string ToString() + { + return _Name; + } + } + public partial class AnnotationTypeInfo + { + public override string ToString() + { + return _Name; + } + } +} diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ColorTab.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ColorTab.cs new file mode 100644 index 00000000..8c5bb647 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ColorTab.cs @@ -0,0 +1,100 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace VEPROMS.CSLA.Library +{ + public static class ColorTab + { + private static Dictionary ColorIndx = null; + // This dictionary takes a color name and converts it to the rtf string: + private static Dictionary ColorRtf = null; + public enum E_Colors : int + { + black = 1, blue, green, cyan, red, magenta, brown, lightgray, darkgray, lightblue, lightgreen, + lightcyan, lightred, lightmagenta, yellow, white, ro, editbackground + } + #region ColorIndex + // Do I need this anymore.... I was using it when entire color table was in the rtf box. + public static int GetIndex(string color) + { + // if the dictionary hasn't been set yet, + if (ColorIndx==null) + { + ColorIndx = new Dictionary(); + ColorIndx["black"] = 1; + ColorIndx["blue"] = 2; + ColorIndx["green"] = 3; + ColorIndx["cyan"] = 4; + ColorIndx["red"] = 5; + ColorIndx["magenta"] = 6; + ColorIndx["brown"] = 7; + ColorIndx["lightgray"] = 8; + ColorIndx["darkgray"] = 9; + ColorIndx["lightblue"] = 10; + ColorIndx["lightgreen"] = 11; + ColorIndx["lightcyan"] = 12; + ColorIndx["lightred"] = 13; + ColorIndx["lightmagenta"] = 14; + ColorIndx["yellow"] = 15; + ColorIndx["white"] = 16; + ColorIndx["ro"] = 17; + ColorIndx["trans"] = 18; + ColorIndx["editbackground"] = 19; + } + return ColorIndx[color]; + } + #endregion + #region ColorRtf + // This gets the rtf color table string for the input color. + public static string GetTableString(string color) + { + Dictionary ColorIndx = new Dictionary(); + if (ColorRtf == null) + { + ColorRtf = new Dictionary(); + + // color table, from 16-bit code, is defined as (in order): + // black=0,0,0 + // blue=0,0,255 + // green=0,155,12 + // cyan=0,136,159 + // red=255,0,0 + // magenta=202,28,175 + // brown=128,64,0 + // lightgray=0,0,0 + // darkgray=0,0,0 + // lightblue=0,0,255 + // lightgreen=0,255,0 + // lightcyan=0,0,255 + // lightred=209,29,183 + // lightmagenta=255,0,255 + // yellow=255,0,0 + // white=128,128,128 + // ro=255,128,0 + // editbackground=192,192,192 + ColorRtf["black"] = "\\red0\\green0\\blue0;"; + ColorRtf["blue"] = "\\red0\\green0\\blue255;"; + ColorRtf["green"] = "\\red0\\green155\\blue12;"; + ColorRtf["cyan"] = "\\red0\\green136\\blue159;"; + ColorRtf["red"] = "\\red255\\green0\\blue0;"; + ColorRtf["magenta"] = "\\red202\\green28\\blue175;"; + ColorRtf["brown"] = "\\red128\\green64\\blue0;"; + ColorRtf["lightgray"] = "\\red100\\green100\\blue100;"; + ColorRtf["darkgray"] = "\\red10\\green10\\blue10;"; + ColorRtf["lightblue"] = "\\red0\\green0\\blue255;"; + ColorRtf["lightgreen"] = "\\red0\\green255\\blue0;"; + ColorRtf["lightcyan"] = "\\red0\\green0\\blue255;"; + ColorRtf["lightred"] = "\\red209\\green29\\blue183;"; + ColorRtf["lightmagenta"] = "\\red255\\green0\\blue255;"; + ColorRtf["yellow"] = "\\red255\\green0\\blue0;"; + ColorRtf["white"] = "\\red128\\green128\\blue128;"; + ColorRtf["ro"] = "\\red255\\green128\\blue0;"; + ColorRtf["trans"] = "\\red255\\green128\\blue0;"; + ColorRtf["editbackground"] = "\\red192\\green192\\blue192;"; + } + return ColorRtf[color]; + } + #endregion + } +} diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs new file mode 100644 index 00000000..a77a66c8 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Csla; +using Csla.Data; +using System.Xml; +using System.Data.SqlClient; +using System.Data; + +namespace VEPROMS.CSLA.Library +{ + public partial class Content + { + public override string ToString() + { + return string.Format("{0} {1}", Number, Text); + } + } + public partial class ContentInfo + { + public override string ToString() + { + return string.Format("{0} {1}", Number, Text); + } + //public XmlNode ToXml(XmlNode xn) + //{ + // XmlNode nd = xn.OwnerDocument.CreateElement("Content"); + // xn.AppendChild(nd); + // AddAttribute(nd, "Number", _Number); + // AddAttribute(nd, "Text", _Text); + // AddAttribute(nd, "FormatID", _FormatID); + // AddAttribute(nd, "Config", _Config); + // return nd; + //} + //public void AddAttribute(XmlNode xn, string name, object o) + //{ + // if (o != null && o.ToString() != "") + // { + // XmlAttribute xa = xn.OwnerDocument.CreateAttribute(name); + // xa.Value = o.ToString(); + // xn.Attributes.Append(xa); + // } + //} + } + public partial class ContentInfoList + { + public static ContentInfoList GetList(int? itemID) + { + try + { + ContentInfoList tmp = DataPortal.Fetch(new ContentListCriteria(itemID)); + ContentInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ItemInfoList.GetChildren", ex); + } + } + [Serializable()] + private class ContentListCriteria + { + public ContentListCriteria(int? itemID) + { + _ItemID = itemID; + } + private int? _ItemID; + public int? ItemID + { + get { return _ItemID; } + set { _ItemID = value; } + } + } + private void DataPortal_Fetch(ContentListCriteria criteria) + { + this.RaiseListChangedEvents = false; + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "vesp_ListContentsByItemID"; + cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) + { + ContentInfo contentInfo = new ContentInfo(dr); + this.Add(contentInfo); + } + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + Database.LogException("ContentInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("ContentInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + } +} diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/DisplayText.cs b/PROMS/VEPROMS.CSLA.Library/Extension/DisplayText.cs new file mode 100644 index 00000000..a87ceb1b --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Extension/DisplayText.cs @@ -0,0 +1,735 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows.Forms; +using System.Text.RegularExpressions; +using System.Drawing; + +namespace VEPROMS.CSLA.Library +{ + public class DisplayText + { + #region Properties + private ItemInfo _itemInfo; + // list of 'pieces of text' for this item. Pieces include symbols, ros, + // transitions & plain text. + private List _DisplayTextElementList; + public List DisplayTextElementList + { + get { return _DisplayTextElementList; } + set { _DisplayTextElementList = value; } + } + // dictionary for the font table for this item. Note that this may + // go away (it is not really used). + private Dictionary _dicRtfFontTable; + public Dictionary dicRtfFontTable + { + get { return _dicRtfFontTable; } + set { _dicRtfFontTable = value; } + } + private VE_Font _textFont; // Font from format for this item + public VE_Font TextFont + { + get { return _textFont; } + set { _textFont = value; } + } + public string OriginalText; // compare for save to see if change. + #endregion + #region Constructors + /// + /// DisplayText constructor: + /// Creates a DisplayText object that converts the database text into a list of + /// displayTextElement elements. + /// Arguments are: + /// ItemInfo itemInfo - the item whose text will be resolved + /// E_EditPrintMode ep_mode - edit or print. + /// E_ViewMode vw_mode - view or edit. + /// + public DisplayText(ItemInfo itemInfo, E_EditPrintMode epMode, E_ViewMode vwMode) + { + _itemInfo = itemInfo; + DisplayTextElementList = new List(); + OriginalText = itemInfo.MyContent.Text; + TextFont = GetItemFont(); + string text = InsertRtfStyles(); + + // if in print mode or view mode, do replace words. Only if in edit mode are replace + // words left as is. + FormatInfo format = itemInfo.ActiveFormat; + if (epMode == E_EditPrintMode.PRINT || vwMode == E_ViewMode.VIEW) text = DoReplaceWords(text, format); + + // displayTextElement List items are created for anything that is handled differently in RTB, i.e. + // symbols, ros, trans, text. + int startIndex = 0; + int index = -1; + while ((index = FindTokenChar(text, startIndex))>-1) + { + // Do any 'plain' text that preceeds the token. + if (index > startIndex) DoTextElement(text, startIndex, index); + + // Now do any other types + if (text[index] == '\x15') + index = DoRO(text, index); + else if (text[index] == '\x252C' || text[index]=='\x2566') + index = DoTran(text, index); + else + index = DoSymbol(text, startIndex, index); + startIndex = index; // +1; + if (startIndex >= text.Length) break; + } + // Add any remaining text. + if (startIndex < text.Length) DoTextElement(text, startIndex, index); + } + #endregion + #region SaveData + public bool Save(RichTextBox rtb) + { + try + { + List origList = GetLinkList(DisplayTextElementList); + // massage string to store in DisplayTextElementList... + RtfToDisplayTextElements(rtb); + // take the list & convert to data in the format to save to the database. + StringBuilder sret = new StringBuilder(); + foreach (displayTextElement vte in DisplayTextElementList) + { + if (vte.Type == E_TextElementType.TEXT || vte.Type == E_TextElementType.SYMBOL) + sret.Append(vte.Text); + else if (vte.Type == E_TextElementType.RO) + sret.Append(ToData_RO((displayLinkElement)vte)); + else if (vte.Type == E_TextElementType.TRANS_Single) + sret.Append(ToData_Trans((displayLinkElement)vte)); + } + string modtext = sret.ToString(); + if (modtext != OriginalText) + { + Item itm = _itemInfo.Get(); + // check for different text, i.e. text from this itm doesn't match + // original text. + if (OriginalText != itm.MyContent.Text) + { + Console.WriteLine("Save Failed because text changed outside of this edit session."); + return false; + } + // Compare ro/transition lists and delete or add any to the item for any ros/transitions that have been + // added/deleted or modified. + ProcessRoTranChanges(itm, origList); + itm.MyContent.Text = modtext; + itm.Save(); + } + else + return true; // no text changed, but did not fail so return true. + } + catch (Exception ex) + { + Console.WriteLine("Save Failed with error: {0}", ex.Message); + return false; + } + return true; + } + private void ProcessRoTranChanges(Item itm, List origList) + { + // go through list. Note that only linked items are in the origList. + // 1) delete any that are in origList but not in the DisplayTextElementList + // (that represents the current text & links) + // 2) add any that are only in DisplayTextElementList + // 3) delete/add for modify? + + // delete first - if in original, but not in current list, delete the one + // in the original list. + foreach (displayLinkElement odte in origList) + { + bool found = false; + foreach (displayTextElement dte in DisplayTextElementList) + { + if (dte.Type == odte.Type) + { + displayLinkElement l_dte = (displayLinkElement)dte; + if (odte.Link == l_dte.Link) + { + found = true; + break; + } + } + } + // remove the link element from the item. + if (!found) + { + // Get record id for ro or trans and then find the associated ro or transition + // in the item's list. remove it. + int recid = -1; + if (odte.Type != E_TextElementType.RO) + { + int sp = odte.Link.IndexOf(" ") + 1; // get past tran type + string srecid = odte.Link.Substring(sp, odte.Link.IndexOf(" ", sp) - sp); + recid = System.Convert.ToInt32(srecid); + foreach (ContentTransition ct in itm.MyContent.ContentTransitions) + { + if (ct.TransitionID == recid) + { + itm.MyContent.ContentTransitions.Remove(ct); + break; + } + } + } + else + { + int sp = odte.Link.IndexOf(" "); + //rousageid starts after "#Link:ReferencedObject:", i.e. index in link of 23 + string srecid = odte.Link.Substring(23, sp-23); + recid = System.Convert.ToInt32(srecid); + foreach (ContentRoUsage cr in itm.MyContent.ContentRoUsages) + { + if (cr.ROUsageID == recid) + { + itm.MyContent.ContentRoUsages.Remove(cr); + break; + } + } + } + } + } + // now do insert, i.e. in new list, but not in old. + foreach (displayTextElement dte in DisplayTextElementList) + { + bool found = false; + if (dte.Type == E_TextElementType.RO || dte.Type == E_TextElementType.TRANS_Single || dte.Type == E_TextElementType.TRANS_Range) + { + foreach (displayLinkElement odte in origList) + { + if (dte.Type == odte.Type) + { + // if the link is the same, it exists, so no action is required. + displayLinkElement l_dte = (displayLinkElement)dte; + if (odte.Link == l_dte.Link) + { + found = true; + break; + } + } + } + // Insert the link (ro or transition) to the item + if (!found) + { + Console.WriteLine("New ro or trans"); + } + } + } + } + private List GetLinkList(List locDisplayTextElementList) + { + List retList = new List(); + foreach (displayTextElement vte in locDisplayTextElementList) + { + if (vte.Type == E_TextElementType.RO || vte.Type == E_TextElementType.TRANS_Range || vte.Type == E_TextElementType.TRANS_Single) + { + displayLinkElement tmp = (displayLinkElement)vte; + displayLinkElement copy_vte = new displayLinkElement(); + copy_vte.Type = tmp.Type; + copy_vte.Link = tmp.Link; + copy_vte.Text = tmp.Text; + retList.Add(copy_vte); + } + } + return retList; + } + private void RtfToDisplayTextElements(RichTextBox rtb) + { + // GetFontTable returns a non-negative number font number in the + // font table for the unicode font, if it is used (otherwise -1) + //int unicodeFont = GetFontTable(rtb.Rtf); + + // strip off all rtf commands... + string noExtraRtfStr = StripRtfCommands(rtb.Rtf); + //Console.WriteLine("StripRtf: {0}", noExtraRtfStr); + + DisplayTextElementList.Clear(); + int startIndex = 0; + int index = -1; + while ((index = FindRtfChar(noExtraRtfStr, startIndex)) > -1) + { + int fndindx = -1; + // Do any 'plain' text that preceeds the token. + if (index > startIndex) + index = SaveTextElement(noExtraRtfStr, startIndex, index); + if ((fndindx = noExtraRtfStr.IndexOf("\\protect")) == index) + index = SaveLink(noExtraRtfStr, index); + else + index = SaveSymbolTE(noExtraRtfStr, index); + startIndex = index + 1; + if (startIndex >= noExtraRtfStr.Length) break; + } + // Add any remaining text. + if (startIndex < noExtraRtfStr.Length) DoTextElement(noExtraRtfStr, startIndex, index); + //Console.WriteLine(noExtraRtfStr); + } + private int SaveTextElement(string data, int startIndex, int index) + { + displayTextElement vte = new displayTextElement(); + vte.Type = E_TextElementType.TEXT; + int len = (index == -1) ? data.Length - startIndex : index - startIndex; + vte.Text = data.Substring(startIndex, len); + DisplayTextElementList.Add(vte); + return index; + } + private int SaveSymbolTE(string data, int startIndex) + { + displayLinkElement vte = new displayLinkElement(); + vte.Type = E_TextElementType.SYMBOL; + // symbols are just the unicode/rtf command, no font associated with it + // by the time it gets here... A symbol can be represented by \'xy or \uxyz? + // if the \'xy is used the length of the symbol number will always be two, + // otherwise find the index of the '?' to find the end. + int endindx = -1; + if (data[startIndex + 1] == '\'') endindx = startIndex + 3; + else endindx = data.IndexOf("?", startIndex); + if (endindx == -1) return startIndex; // not found - error + vte.Text = data.Substring(startIndex, endindx - startIndex + 1); + DisplayTextElementList.Add(vte); + return endindx + 1; + } + private int SaveLink(string data, int startIndex) + { + displayLinkElement vte = new displayLinkElement(); + + // first find if RO or trans, the RO has a #R. + int istart = data.IndexOf("#Link:", startIndex); + if (data[istart + 6] == 'R') return SaveROTE(data, startIndex); + else if (data.Substring(istart+6,11) == "TransitionR") + return SaveTranTE(data, startIndex, E_TextElementType.TRANS_Range); + return SaveTranTE(data, startIndex, E_TextElementType.TRANS_Single); + } + private int SaveTranTE(string data, int startIndex, E_TextElementType type) + { + displayLinkElement vte = new displayLinkElement(); + vte.Type = type; + // \protect {transition text} \v #Link:Transition(Range): 1 2 3\protect0\v0 where 1 2 3 are transition type and ids + int indx = data.IndexOf("\\v #Link:Transition", startIndex); + vte.Text = data.Substring(startIndex + 9, indx - startIndex - 9); // get past \protect + int iend = data.IndexOf("\\protect0\\v0", indx); + if (iend == -1) iend = data.IndexOf("\\v0\\protect0", indx); + // get past \v #Link:Transition or \v #Link:TransitionRange + int bindx = indx + 3; + //if (type == E_TextElementType.TRANS_Range) bindx += 5; + vte.Link = data.Substring(bindx, iend - bindx); + DisplayTextElementList.Add(vte); + return iend + 11; // get past the \protect0\vo + } + private int SaveROTE(string data, int startIndex) + { + displayLinkElement vte = new displayLinkElement(); + vte.Type = E_TextElementType.RO; + // \protect {rovalue} \v #Link:ReferencedObject (RoUsageId) {ROID}\protect0\v0 + int indx = data.IndexOf("\\v #Link:ReferencedObject", startIndex); + vte.Text = data.Substring(startIndex + 9, indx - startIndex - 9); // get past \protect + int iend = data.IndexOf("\\protect0\\v0", indx); + if (iend == -1) iend = data.IndexOf("\\v0\\protect0", indx); + vte.Link = data.Substring(indx + 3, iend - indx - 3); // get past \v #Link:ReferencedObject + DisplayTextElementList.Add(vte); + return iend + 11; // get past the \protect0\vo + } + private int FindRtfChar(string text, int startIndex) + { + int prindx = text.IndexOf("\\protect", startIndex); + int symindx1 = text.IndexOf("\\'", startIndex); + int symindx2 = text.IndexOf("\\u", startIndex); + if (symindx2 > -1) + { + if (text[symindx2+2] == 'l') symindx2 = -1; // don't process underlines + } + if (prindx == -1 && symindx1 == -1 && symindx2 == -1) return -1; + if (prindx == -1) prindx = text.Length + 1; + if (symindx1 == -1) symindx1 = text.Length + 1; + if (symindx2 == -1) symindx2 = text.Length + 1; + + // Which token has smallest number, to determine which item is next + // in the string. If it is a symbol - see if it has a font specifier + // first. + int symindx = symindx1 < symindx2 ? symindx1 : symindx2; + int smallest = (prindx < symindx ? prindx : symindx); + return smallest; + } + private int GetFontTable(string rtf) + { + dicRtfFontTable = new Dictionary(); + // return unicode (symbol) font number, if it exists, to expedite finding + // the font for symbols. + int unicodeFont = -1; + int bindx = rtf.IndexOf(@"{\fonttbl"); + if (bindx < -1) return -1; + int eindx = rtf.IndexOf("}}", bindx); + // get font table string and then do regular expressions to get font number + // with font name. + string tbl = rtf.Substring(bindx + 9, eindx - bindx - 8); + tbl = tbl.Replace("{", "<"); + tbl = tbl.Replace("}", ">"); + string pat = @"(?:<\\f)([0-9]+)(?:[\S]+ )([\w ]+)"; + StringBuilder sb = new StringBuilder(); + foreach (Match m in Regex.Matches(tbl, pat)) + { + int num = Convert.ToInt32(m.Result("${1}")); + string nam = m.Result("${2}"); + dicRtfFontTable.Add(num, nam); + if ((unicodeFont == -1) && (nam == "Arial Unicode MS")) unicodeFont = num; + } + return unicodeFont; + } + private string RemoveRtfStyles(string rtf) + { + string retval = rtf; + // remove rtf commands for any styles that were added. Note that if + // the entire item has a style, and also contains 'pieces' of text with + // the same style, the underlying rtf box removes the embedded rtf commands, + // for example, if the entire step is bolded, and 'THEN' has bold on/off + // surrounding it, the rtf box removes the bold around the 'THEN' + // These remove the command with a following space or the command alone, + // either case may exist, because if there are rtf commands following the + // style command, there will be no space character following the style command. + if ((TextFont.Style & E_Style.BOLD) > 0) + { + retval = Regex.Replace(retval, @"\\b0 ?", ""); + retval = Regex.Replace(retval, @"\\b ?",""); + } + if ((TextFont.Style & E_Style.UNDERLINE) > 0) + { + retval = Regex.Replace(retval, @"\\ul0 ?", ""); + retval = Regex.Replace(retval, @"\\ul ?", ""); + } + if ((TextFont.Style & E_Style.ITALICS) > 0) + { + retval = Regex.Replace(retval, @"\\i0 ?", ""); + retval = Regex.Replace(retval, @"\\i ?", ""); + } + return retval; + } + public string ReplaceRTFClause(Match m) + { + switch (m.Value[1]) + { + case 'u': + if (Regex.IsMatch(m.Value, @"\\u[0-9]+")) + return m.Value; // Special Charcaters + if (Regex.IsMatch(m.Value, @"\\ulnone")) + return m.Value; + if (Regex.IsMatch(m.Value, @"\\ul.*")) + return m.Value; // Underline + break; + case '\'': // Special Character + return m.Value; + case 'b': // Bold + return m.Value; + case 's': // sub or super.... + if (m.Value == @"\sub") return m.Value; + if (m.Value == @"\super") return m.Value; + break; + case 'n': // nosubsuper... + if (m.Value == @"\nosupersub") return m.Value; + break; + case 'i': // Italics + return m.Value; + case 'v': // save link hidden info + if (m.Value == @"\v") return m.Value; // part of link + if (Regex.IsMatch(m.Value, @"\\v0")) + return m.Value; // hidden info off + break; + case 'p': + if (m.Value == @"\par") return "\r\n"; + if (m.Value == @"\protect") + return m.Value; + if (m.Value == @"\protect0") + return m.Value; + break; + } + return "";//Strip All + } + private string StripRtfCommands(string rtf) + { + string retval = Regex.Replace(rtf, @"[\r\n]", "", RegexOptions.Singleline); // Strip Carriage Returns and Newlines + retval = Regex.Replace(retval, @"^\{(.*)\}$", "$1", RegexOptions.Singleline); // Strip Opening and Closing Braces + retval = Regex.Replace(retval, @"\{[^{]*?\}", "", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces + retval = Regex.Replace(retval, @"\{[^{]*?\}", "", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces + retval = Regex.Replace(retval, @"\\[^ \\?]+", new MatchEvaluator(ReplaceRTFClause)); // take backslash xyz and evaluates them + // remove a space if there is one as the first character.. + if (retval[0]==' ')retval = retval.Remove(0, 1); + // remove \r\n at end of string - this was added with the \par at the end of string by the rtf box + if (retval.Substring(retval.Length - 2, 2) == "\r\n") retval = retval.Remove(retval.Length - 2, 2); + retval = RemoveRtfStyles(retval); + + return retval; + } + private string ToData_RO(displayLinkElement vte) + { + // get past the #Link:ReferencedObject part of the link. + return String.Format("\x15\\v RO\\v0 {0}\\v #{1}\\v0", vte.Text, vte.Link.Substring(23, vte.Link.Length-23)); + } + private string ToData_Trans(displayLinkElement vte) + { + char trchar = vte.Type == E_TextElementType.TRANS_Single ? '\x252C' : '\x2566'; + int indx = vte.Type == E_TextElementType.TRANS_Single ? 16 : 21; + return String.Format("{0}\\v TRAN\\v0 {1}\\v {2}\\v0", trchar, vte.Text, vte.Link.Substring(indx, vte.Link.Length-indx)); + } + #endregion + #region StyleData + private VE_Font GetItemFont() + { + VE_Font font = null; + FormatInfo format = _itemInfo.ActiveFormat; + int type = (int)_itemInfo.MyContent.Type; + switch (type/10000) + { + case 0: // procedure + font = format.PlantFormat.FormatData.Font; + break; + case 1: // section + font = format.PlantFormat.FormatData.SectData.SectionHeader.Font; + break; + case 2: // step types + int typindx = type - 20000; // what to do for other types rather than steps + font = format.PlantFormat.FormatData.StepDataList[typindx].Font; + break; + } + TextFont = font; + return font; + } + private string InsertRtfStyles() + { + StringBuilder sb = new StringBuilder(_itemInfo.MyContent.Text); + if ((TextFont.Style & E_Style.BOLD)>0) + { + sb.Insert(0, "\\b "); + sb.Append("\\b0 "); + } + if ((TextFont.Style & E_Style.UNDERLINE) > 0) + { + sb.Insert(0, "\\ul "); + sb.Append("\\ul0 "); + } + if ((TextFont.Style & E_Style.ITALICS) > 0) + { + sb.Insert(0, "\\i "); + sb.Append("\\i0 "); + } + return sb.ToString(); + } + #endregion + #region DoListElements + private int FindTokenChar(string txt, int startIndex) + { + // tokens are ro, transitions and possible symbol + char[] tok = { '\x15', '\x252C', '\x2566', '\\' }; + bool done = false; + // If there is only an rtf token from the indexed position on, don't return the + // IndexOfAny index value, because it will by one character past the '\' and throw + // of the return value of where in the string the text should be saved. For example + // for the string '\b text \v somevalue \v0\b0', the first time through the while + // loop has the index at the '\b' char of the b0. + //int savstartIndex = startIndex; + while (!done) + { + int indx = txt.IndexOfAny(tok, startIndex); + if (indx < 0) return indx; + if (txt[indx] != '\\') return indx; + // see if symbol (but not underline) or another rtf command: has a 'u' + // followed by a non-underline or single quote, and if so, return it. + // Otherwise, get next index, must have been a slash or other rtf command. + if (((txt[indx + 1] == 'u' && txt[indx + 2] != 'l')) || (txt[indx + 1] == '\'')) return indx; + startIndex=indx+1; + } + return -1; + } + private int DoTextElement(string text, int startIndex, int index) + { + displayTextElement vte = new displayTextElement(); + vte.Type = E_TextElementType.TEXT; + int len = (index == -1) ? text.Length - startIndex : index - startIndex; + vte.Text = text.Substring(startIndex, len); + DisplayTextElementList.Add(vte); + return index+1; + } + private string CreateLink(E_TextElementType type, string linktxt) + { + string retlink = ""; + if (type == E_TextElementType.RO) + retlink = "#Link:ReferencedObject:" + linktxt; + else if (type == E_TextElementType.TRANS_Single) + retlink = "#Link:Transition:" + linktxt; + else + retlink = "#Link:TransitionRange:" + linktxt; + + return retlink; + } + private int DoRO(string text, int index) + { + displayLinkElement vte = new displayLinkElement(); + vte.Type = E_TextElementType.RO; + // ro has form \v RO\v0 9.5 psig\v #1 0001000000ec0000 \v0 - so find second + // \v0 to end the string. + int istart = text.IndexOf("\\v0",index) + 4; + int iend = text.IndexOf("\\v", istart); + vte.Text = text.Substring(istart, iend - istart); + istart = text.IndexOf("#", iend) + 1; + iend = text.IndexOf("\\v0", istart); + vte.Link = CreateLink(vte.Type, text.Substring(istart, iend - istart)); + DisplayTextElementList.Add(vte); + // return the position past the end of the \v0. There is a space after the + // \v0 so account for that. + return iend + 4; + } + private string FixTransition(string link, string text) + { + int transitionID = Convert.ToInt32(link.Split(" ".ToCharArray())[1]); + // Find the transition + foreach (TransitionInfo ti in _itemInfo.MyContent.ContentTransitions) + { + if (ti.TransitionID == transitionID) + { + string path = ti.PathTo.Replace(" Section PROCEDURE STEPS ", ", "); + path = path.Replace(" Section PROCEDURE STEPS", ""); + return path; + } + } + return text; + } + private int DoTran(string text,int index) + { + displayLinkElement vte = new displayLinkElement(); + // transition (not range) has form \v TRAN\v0 (resolved transition text)\v type fromid toid [rangeid, if range]\v0 + int istart = text.IndexOf("\\v0", index) + 4; + int iend = text.IndexOf("\\v", istart); + vte.Text = text.Substring(istart, iend - istart); // this stores the resolved transition text + istart = iend + 3; // get to transition type. + iend = text.IndexOf("\\v0", istart); + vte.Text = FixTransition(text.Substring(istart, iend - istart), vte.Text); + // Determine whether it is single or range transition. Can tell by number of spaces in + // link string. + string[] parts = text.Substring(istart, iend - istart).Split(" ".ToCharArray()); + if (parts.Length == 3) vte.Type = E_TextElementType.TRANS_Single; + else vte.Type = E_TextElementType.TRANS_Range; + vte.Link = CreateLink(vte.Type, text.Substring(istart, iend - istart)); + DisplayTextElementList.Add(vte); + // return the position past the end of the \v0. There is a space after the + // \v0 so account for that. + return iend + 4; + } + private int DoSymbol(string text, int startIndex, int index) + { + displayTextElement vte = new displayTextElement(); + vte.Type = E_TextElementType.SYMBOL; + // symbols are the unicode/rtf command. A symbol can be represented by \'xy or + // in the text from the database \uxyz?. If the \'xy is used the length of the + // symbol number will always be two, otherwise find the index of the '?' to + // find the end. + int endindx = -1; + if (text[index + 1] == '\'') endindx = index + 3; + else endindx = text.IndexOf("?", index); + vte.Text = text.Substring(index, endindx - index + 1); + DisplayTextElementList.Add(vte); + // return the position just past the symbol. + return endindx+1; + } + #endregion + #region ReplaceWords + private ReplaceStr _rs; + private string ReplaceIt(Match m) + { + string s = m.ToString(); + string t = s.Replace(_rs.ReplaceWord, _rs.ReplaceWith); + return m.ToString().Replace(_rs.ReplaceWord, _rs.ReplaceWith); + } + private string DoReplaceWords(string Text, FormatInfo format) + { + ReplaceStrList rsl = format.PlantFormat.FormatData.SectData.ReplaceStrList; + foreach (ReplaceStr rs in rsl) + { + if (_itemInfo.MyContent.Type < 20000) return Text; // for now only replace in steps. + bool replaceit = false; + + // note that the order of this check is important. Check in this order... + // background here + if (_itemInfo.IsHigh && (rs.Flag & E_ReplaceFlags.HIGH)>0) replaceit = true; + else if ((_itemInfo.IsTable || _itemInfo.IsFigure) && (rs.Flag & E_ReplaceFlags.TABLE) > 0) replaceit = true; + else if (_itemInfo.IsInRNO && (rs.Flag & E_ReplaceFlags.RNO) > 0) replaceit = true; + else if (_itemInfo.IsCaution && (rs.Flag & E_ReplaceFlags.CAUTION) > 0) replaceit = true; + else if (_itemInfo.IsNote && (rs.Flag & E_ReplaceFlags.NOTE) > 0) replaceit = true; + else if (_itemInfo.IsInFirstLevelSubStep && (rs.Flag & E_ReplaceFlags.SUBSTEP) > 0) replaceit = true; + else if (_itemInfo.IsAccPages & (rs.Flag & E_ReplaceFlags.ATTACH) > 0) replaceit = true; + + if (replaceit) + { + // CASEINSENS: Do ReplaceWords for all words that match, regardless of case, and replace + // with the ReplaceWith string as is + if ((rs.Flag & E_ReplaceFlags.CASEINSENS) > 0) + { + string res = ""; + string fortest = Text.ToUpper(); + string pat = @"(?<=\W|^)" + rs.ReplaceWord.ToUpper() + @"(?=\W|$)"; + int cpindx = 0; + foreach (Match m in Regex.Matches(fortest, pat)) + { + res += Text.Substring(cpindx, m.Index-cpindx); + cpindx += (m.Index - cpindx); + res += rs.ReplaceWith; + cpindx += rs.ReplaceWord.Length; + } + if (cpindx < Text.Length) res += Text.Substring(cpindx, Text.Length - cpindx); + Text = res; + } + // CASEINSENSALL: Do ReplaceWords for all words that match the ReplaceWord, regardless of case + else if ((rs.Flag & E_ReplaceFlags.CASEINSENSALL) > 0) + { + // not in hlp + } + // CASEINSENSFIRST: Do ReplaceWords for all words that exactly match the ReplaceWord, + // except the case where the first character may be different + else if ((rs.Flag & E_ReplaceFlags.CASEINSENSFIRST) > 0) + { + // not in hlp + } + else + { + string pat = @"(?<=\W|^)" + rs.ReplaceWord + @"(?=\W|$)"; + Text = Regex.Replace(Text, pat, rs.ReplaceWith); + } + + } + } + return Text; + } + #endregion + } + #region displayTextElementClass + public enum E_TextElementType : uint + { + TEXT = 0, + SYMBOL = 1, + RO = 2, + TRANS_Single = 3, + TRANS_Range = 4 + }; + public class displayTextElement + { + private E_TextElementType _Type; + public E_TextElementType Type + { + get { return _Type; } + set { _Type = value; } + } + private string _Text; + public string Text + { + get { return _Text; } + set { _Text = value; } + } + } + public class displayLinkElement : displayTextElement + { + private string _Link; + public string Link + { + get { return _Link; } + set { _Link = value; } + } + } + #endregion + +} diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/DocVersionExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/DocVersionExt.cs new file mode 100644 index 00000000..ac5e75cc --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Extension/DocVersionExt.cs @@ -0,0 +1,155 @@ +// ======================================================================== +// Copyright 2006 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Collections.Generic; + +namespace VEPROMS.CSLA.Library +{ + public partial class DocVersion: IVEDrillDown + { + #region VersionType + public VersionTypeEnum eVersionType + { + get { return (VersionTypeEnum)_VersionType; } + set { _VersionType = (int)value; } + } + #endregion + #region DocVersion Config + [NonSerialized] + private DocVersionConfig _DocVersionConfig; + public DocVersionConfig DocVersionConfig + { + get + { + if (_DocVersionConfig == null) + { + _DocVersionConfig = new DocVersionConfig(this); + _DocVersionConfig.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(_DocVersionConfig_PropertyChanged); + } + return _DocVersionConfig; + } + } + private void _DocVersionConfig_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) + { + Config = _DocVersionConfig.ToString(); + } + #endregion + public override string ToString() + { + return string.Format("{0} - {1}", Name, Title); + } + #region IVEDrillDown + public System.Collections.IList GetChildren() + { + return null; + } + public bool HasChildren + { + get { return _ItemID > 0; } + } + public IVEDrillDown ActiveParent + { + get + { + return MyFolder; + } + } + public Format ActiveFormat + { + get { return LocalFormat != null ? LocalFormat : ActiveParent.ActiveFormat; } + } + public Format LocalFormat + { + get { return MyFormat; } + } + public DynamicTypeDescriptor MyConfig + { + get { return DocVersionConfig; } + } + #endregion + } + public partial class DocVersionInfo:IVEDrillDownReadOnly + { + #region DocVersion Config + [NonSerialized] + private DocVersionConfig _DocVersionConfig; + public DocVersionConfig DocVersionConfig + { get { return (_DocVersionConfig != null ? _DocVersionConfig : _DocVersionConfig = new DocVersionConfig(this));} } + private void DocVersionConfigRefresh() + { + _DocVersionConfig = null; + } + #endregion + ItemInfoList _iil = null; + public ItemInfoList Procedures + { get { return (_iil != null ? _iil: _iil = ItemInfoList.GetList(_ItemID,(int)E_FromType.Procedure)); } } + #region IVEReadOnlyItem + public System.Collections.IList GetChildren() + { + return Procedures; + } + //public bool ChildrenAreLoaded + //{ + // get { return _iil == null; } + //} + public bool HasChildren + { + get { return _ItemID > 0; } + } + public IVEDrillDownReadOnly ActiveParent + { + get + { + return MyFolder; + } + } + public FormatInfo ActiveFormat + { + get { return LocalFormat != null ? LocalFormat : ActiveParent.ActiveFormat; } + } + public FormatInfo LocalFormat + { + get { return MyFormat; } + } + public DynamicTypeDescriptor MyConfig + { + get { return Get().DocVersionConfig; } + } + //public bool HasStandardSteps() + //{ return false; } + public override string ToString() + { + return string.Format("{0} - {1}", Name, Title); + } + //public string ToString(string str,System.IFormatProvider ifp) + //{ + // return ToString(); + //} + #endregion + #region Extension + partial class DocVersionInfoExtension : extensionBase + { + public override void Refresh(DocVersionInfo tmp) + { + tmp.DocVersionConfigRefresh(); + } + } + #endregion + } + public enum VersionTypeEnum : int + { + WorkingDraft = 0, Temporary = 1, Revision = 128, Approved = 129 + } +} diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs new file mode 100644 index 00000000..8a8a7587 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs @@ -0,0 +1,138 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; + +namespace VEPROMS.CSLA.Library +{ + public partial class DocumentInfo + { + public string DocumentTitle + { + get + { + if (_LibTitle == "") return string.Format("Document {0}", _DocID); + return _LibTitle; + } + } + } + public class DSOFile : IDisposable + { + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #region Fields + private bool _IsDisposed; + private static string _TemporaryFolder = null; + private DocumentInfo _MyDocument = null; + private FileInfo _MyFile = null; + private string _Extension = "DOC"; + #endregion + #region Properties + public static string TemporaryFolder + { + get + { + if (_TemporaryFolder == null) + { + _TemporaryFolder = string.Format(@"C:\Documents and Settings\{0}\Local Settings\Temp", Environment.UserName); + if (!Directory.Exists(TemporaryFolder)) Directory.CreateDirectory(TemporaryFolder); + _TemporaryFolder += @"\VE-PROMS"; + if (!Directory.Exists(TemporaryFolder)) Directory.CreateDirectory(TemporaryFolder); + } + return _TemporaryFolder; + } + } + public DocumentInfo MyDocument + { + get { return _MyDocument; } + set + { + TryDelete(); + _MyDocument = value; + CreateFile(); + } + } + public FileInfo MyFile + { + get { return _MyFile; } + } + public string Extension + { + get { return _Extension; } + set { _Extension = value; } + } + #endregion + #region Private Methods + private void TryDelete() + { + if (_MyDocument == null) return; + if (_MyFile == null) return; + if (_MyFile.Exists) + { + try + { + _MyFile.Delete(); + } + catch (IOException ex) + { + _MyLog.Error("TryDelete",ex); + } + finally + { + _MyFile = null; + _MyDocument = null; + } + } + } + private void CreateFile() + { + if (_MyDocument == null) return; + _MyFile = new FileInfo(string.Format(@"{0}\tmp_{1}." + Extension , TemporaryFolder, MyDocument.DocID)); + FileStream fs = _MyFile.Create(); + fs.Write(MyDocument.DocContent, 0, MyDocument.DocContent.Length); + fs.Close(); + _MyFile.CreationTime = _MyDocument.DTS; + _MyFile.LastWriteTime = _MyDocument.DTS; + } + public void SaveFile() + { + // TODO: Add Try & Catch logic + if (_MyDocument == null) return; + Document doc = _MyDocument.Get(); + FileStream fs = _MyFile.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite); + Byte[] buf = new byte[_MyFile.Length]; + fs.Read(buf,0,buf.Length); + fs.Close(); + doc.DocContent = buf; + doc.UserID = Environment.UserName; + doc.DTS = _MyFile.LastWriteTime; + doc.Save(); + } + #endregion + #region Constructors + public DSOFile(DocumentInfo myDocument) + { + MyDocument = myDocument; + } + #endregion + #region Destructor + ~DSOFile() + { + Dispose(false); + } + public void Dispose() + { + Dispose(false); + GC.SuppressFinalize(this); + } + + protected void Dispose(bool disposing) + { + if (!_IsDisposed) + { + _IsDisposed = true; + TryDelete(); + } + } + #endregion + } +} diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/FolderExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/FolderExt.cs new file mode 100644 index 00000000..95e22bd7 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Extension/FolderExt.cs @@ -0,0 +1,154 @@ +// ======================================================================== +// Copyright 2006 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.Drawing; +using System.Collections.Generic; + +namespace VEPROMS.CSLA.Library +{ + public partial class Folder : IVEDrillDown + { + #region Folder Config + [NonSerialized] + private FolderConfig _FolderConfig; + public FolderConfig FolderConfig + { + get + { + if (_FolderConfig == null) + { + _FolderConfig = new FolderConfig(this); + _FolderConfig.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(_FolderConfig_PropertyChanged); + } + return _FolderConfig; + } + } + public void FolderConfigRefresh() + { + _FolderConfig = null; + } + private void _FolderConfig_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) + { + Config = _FolderConfig.ToString(); + } + #endregion + public override string ToString() + { + return _Title; + } + #region IVEReadOnlyItem + public System.Collections.IList GetChildren() + { + if (FolderDocVersionCount != 0) return FolderDocVersions; + if (ChildFolderCount != 0) return ChildFolders; + return null; + } + public bool HasChildren + { + get { return _FolderDocVersionCount > 0 || _ChildFolderCount > 0; } + } + public IVEDrillDown ActiveParent + { + get + { + return MyParent; + } + } + public Format ActiveFormat + { + get { return LocalFormat != null ? LocalFormat : (ActiveParent != null ? ActiveParent.ActiveFormat : null); } + } + public Format LocalFormat + { + get { return MyFormat; } + } + public DynamicTypeDescriptor MyConfig + { + get { return FolderConfig; } + } + #endregion + } + public partial class FolderInfo:IVEDrillDownReadOnly + { + #region Folder Config (Read-Only) + [NonSerialized] + private FolderConfig _FolderConfig; + public FolderConfig FolderConfig + { get { + return (_FolderConfig != null ? _FolderConfig : _FolderConfig = new FolderConfig(this)); + } } + private void FolderConfigRefresh() + { + _FolderConfig = null; + } + #endregion + #region IVEReadOnlyItem + public System.Collections.IList GetChildren() + { + if(FolderDocVersionCount != 0)return FolderDocVersions; + if (ChildFolderCount != 0) return ChildFolders; + return null; + } + //public bool ChildrenAreLoaded + //{ + // get { return _FolderDocVersions != null || _ChildFolders != null; } + //} + public bool HasChildren + { + get { return _FolderDocVersionCount > 0 || _ChildFolderCount > 0; } + } + public IVEDrillDownReadOnly ActiveParent + { + get + { + return MyParent; + } + } + public FormatInfo ActiveFormat + { + get { return LocalFormat != null ? LocalFormat : ( ActiveParent != null ? ActiveParent.ActiveFormat : null); } + } + public FormatInfo LocalFormat + { + get { return MyFormat; } + } + public DynamicTypeDescriptor MyConfig + { + get { return Get().FolderConfig; } + } + public override string ToString() + { + return string.Format("{0} - {1}", Name, Title); + } + //public string ToString(string str, System.IFormatProvider ifp) + //{ + // return ToString(); + //} + #endregion + public Color BackColor + { get { return FolderConfig.Default_BkColor; } } + #region Extension + partial class FolderInfoExtension : extensionBase + { + public override void Refresh(FolderInfo tmp) + { + tmp.FolderConfigRefresh(); + } + } + #endregion + } +} diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/FontTab.cs b/PROMS/VEPROMS.CSLA.Library/Extension/FontTab.cs new file mode 100644 index 00000000..10f70fc8 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Extension/FontTab.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace VEPROMS.CSLA.Library +{ + public static class FontTab + { + private static Dictionary FontIndx = null; + // This dictionary takes a color name and converts it to the rtf string: + private static Dictionary FontRtf = null; + public enum E_Fonts : int + { + None = 0, PrestigeEliteTall = 64, CourierNew = 2, TimesNewRoman = 0, LetterGothic = 66, Arial = 202, VolianDraw = 70, GothicUltra = 63, LetterGothicTall = 67, VolianScript = 71, ArialUnicode = 35 + } + #region FontIndex + /// + /// GetIndex - Use this to get the number of the font in the font table based on the input + /// string. + /// + /// + /// + public static int GetIndex(string font) + { + // if the dictionary hasn't been set yet, + if (FontIndx==null) + { + FontIndx = new Dictionary(); + FontIndx["Prestige Elite Tall"] = 64; + FontIndx["Courier New"] = 2; + FontIndx["Times New Roman"] = 0; + FontIndx["Letter Gothic"] = 66; + FontIndx["Arial"] = 202; + FontIndx["Volian Draw"] = 70; + FontIndx["Gothic Ultra"] = 63; + FontIndx["Letter Gothic Tall"] = 67; + FontIndx["VolianScript"] = 71; + FontIndx["Arial Unicode"] = 35; + + } + return FontIndx[font]; + } + #endregion + #region ColorRtf + /// + /// GetTableString - Use this to get the string to add to font table based on the input + /// string. + /// + public static string GetTableString(string font) + { + if (FontRtf == null) + { + FontRtf = new Dictionary(); + FontRtf["Prestige Elite Tall"] = "{\\f64\\fmodern\\fcharset2\\fprq1 Prestige Elite Tall;}"; + FontRtf["Courier New"] = "{\\f2\\fmodern\\fcharset0\\fprq1 Courier New;}"; + FontRtf["Times New Roman"] = "{\\f0\\froman\\fcharset0\\fprq2 Times New Roman;}"; + FontRtf["Letter Gothic"] = "{\\f66\\fmodern\\fcharset2\\fprq1 Letter Gothic;}"; + FontRtf["Arial"] = "{\\f1\\fswiss\\fcharset0\\fprq2 Arial;}"; + FontRtf["Volian Draw"] = "{\\f70\\fmodern\\fcharset2\\fprq1 VolianDraw;}"; + FontRtf["Gothic Ultra"] = "{\\f63\\fmodern\\fcharset2\\fprq1 Gothic Ultra;}"; + FontRtf["Letter Gothic Tall"] = "{\\f67\\fmodern\\fcharset2\\fprq1 Letter Gothic Tall;}"; + FontRtf["VolianScript"] = "{\\f71\\fswiss\\fcharset2\\fprq2 VolianScript;}"; + FontRtf["Arial Unicode"] = "{\\f35\\fswiss\\fcharset128\\fprq2 Arial Unicode MS;}"; + } + return FontRtf[font]; + } + #endregion + } +} diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/FormatExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/FormatExt.cs new file mode 100644 index 00000000..6a6ab774 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Extension/FormatExt.cs @@ -0,0 +1,51 @@ +// ======================================================================== +// Copyright 2006 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.Xml; +using System.Drawing; + +namespace VEPROMS.CSLA.Library +{ + public partial class Format + { + #region PlantFormat + //[NonSerialized] + private PlantFormat _PlantFormat; + public PlantFormat PlantFormat + { get { return (_PlantFormat != null ? _PlantFormat : _PlantFormat = new PlantFormat(this)); } } + #endregion + public override string ToString() + { + //return Name; + return PlantFormat.FormatData.Name; + } + } + public partial class FormatInfo + { + #region PlantFormat + //[NonSerialized] + private PlantFormat _PlantFormat; + public PlantFormat PlantFormat + { get { return (_PlantFormat != null ? _PlantFormat : _PlantFormat = new PlantFormat(this.Get())); } } + #endregion + public override string ToString() + { + //return Name; + return PlantFormat.FormatData.Name; + } + } +} diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs new file mode 100644 index 00000000..77986496 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs @@ -0,0 +1,785 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Csla; +using Csla.Data; +using System.Data; +using System.Data.SqlClient; +using System.Xml; +using System.Drawing; + +namespace VEPROMS.CSLA.Library +{ + #region Item + public partial class Item:IVEDrillDown + { + public override string ToString() + { + return string.Format("{0} {1}", MyContent.Number, MyContent.Text); + } + #region IVEDrillDown + public System.Collections.IList GetChildren() + { + return this.MyContent.ContentParts; + } + public bool HasChildren + { + get { return this.MyContent.ContentPartCount > 0; } + } + private IVEDrillDown _ActiveParent=null; + public IVEDrillDown ActiveParent + { + get + { + if (_ActiveParent == null) + { + if (MyPrevious != null) + _ActiveParent = _MyPrevious.ActiveParent; + else + { + if (ItemDocVersionCount > 0) + _ActiveParent = this.ItemDocVersions[0].MyDocVersion; + else + { + if (this.ItemParts == null || this.ItemPartCount == 0) + _ActiveParent = this; + else + _ActiveParent = this.ItemParts[0].MyContent.ContentItems[0].MyItem; + } + } + } + return _ActiveParent==this ? null : _ActiveParent; + } + } + private Format _ActiveFormat=null;// Added to cache ActiveFormat + public Format ActiveFormat + { + get + { + if(_ActiveFormat == null) + _ActiveFormat = (LocalFormat != null ? LocalFormat : ActiveParent.ActiveFormat); + return _ActiveFormat; + } + } + public Format LocalFormat + { + get { return MyContent.MyFormat; } + } + public DynamicTypeDescriptor MyConfig + { + get { return null; } + } + #endregion + } + #endregion + #region ItemInfo + public partial class ItemInfo:IVEDrillDownReadOnly + { + public bool IsType(string type) + { + int stepType = ((int)MyContent.Type) % 10000; + StepDataList sdlist = ActiveFormat.PlantFormat.FormatData.StepDataList; + StepData sd = sdlist[stepType]; + // TODO: RHM20071115 while (sd.Index != 0) + // TODO: RHM20071115 { + // TODO: RHM20071115 if (sd.Type == type) return true; + // TODO: RHM20071115 sd = sdlist[sd.ParentType]; + // TODO: RHM20071115 } + return false; + } + public bool IsCaution + { + get + { + return IsType("CAUTION"); + } + } + public bool IsNote + { + get + { + return IsType("NOTE"); + } + } + public bool IsTable + { + get + { + return IsType("TABLE"); + } + } + public bool IsFigure + { + get + { + return IsType("FIGURE"); + } + } + public bool IsOr + { + get + { + return IsType("OR"); + } + } + public bool IsAnd + { + get + { + return IsType("AND"); + } + } + public bool IsEquipmentList + { + get + { + return IsType("EQUIPMENTLIST"); + } + } + public bool IsTitle + { + get + { + return IsType("TITLE"); + } + } + public bool IsAccPages + { + get + { + return IsType("ACCPAGES"); + } + } + public bool IsParagraph + { + get + { + return IsType("PARAGRAPH"); + } + } + public bool IsDefault + { + get + { + return IsType("DEFAULT"); + } + } + public bool IsContAcSequential + { + get + { + return IsType("CONTACSEQUENTIAL"); + } + } + public bool IsHigh + { + get + { + // check to see if ActiveParent is a section, if so it is a high level step + if (MyContent.Type / 10000 != 2) return false; + ItemInfo parent = (ItemInfo)ActiveParent; + if ((parent.MyContent.Type / 10000) == 1) + return true; + return false; + } + } + public bool IsSequential + { + get + { + if (((MyContent.Type / 10000) == 2) && ((((int)MyContent.Type) % 10000) == 0)) return true; + return false; + } + } + public bool IsRNO + { + get + { + return ((ItemPartCount > 0) && (ItemParts[0].PartType == E_FromType.RNO)); + } + } + public bool IsInRNO + { + get + { + if (IsHigh) return false; + if (IsRNO) return true; + return ((ItemInfo)ActiveParent).IsInRNO; + } + } + public ItemInfo FirstSibling + { + get + { + ItemInfo temp = this; + while (temp.MyPrevious != null) temp = temp.MyPrevious; + return temp; + } + } + public bool IsSubStep + { + get + { + ItemInfo temp = FirstSibling; + return ((temp.ItemPartCount > 0) && (temp.ItemParts[0].PartType == E_FromType.Step)); + } + } + public bool IsInSubStep + { + get + { + if (IsHigh) return false; + if (IsSubStep) return true; + return ((ItemInfo)ActiveParent).IsInSubStep; + } + } + public bool IsInFirstLevelSubStep + { + get + { + ItemInfo temp = FirstSibling; + while (((ItemInfo)temp.ActiveParent).IsHigh == false) temp = ((ItemInfo)temp.ActiveParent).FirstSibling; + return temp.IsSubStep; + } + } + private E_FromType ItemType + { + get + { + if (MyContent.Type == 0) return E_FromType.Procedure; + if (MyContent.Type < 20000) return E_FromType.Section; + return E_FromType.Step; + } + } + public Item GetByType() + { + Item tmp = null; + switch (ItemType) + { + case E_FromType.Procedure: + tmp = Procedure.Get(_ItemID); + break; + //case E_FromType.Section: + // itemInfo = new Section(dr); + // break; + //default: + // itemInfo = new Step(dr); + // break; + } + return tmp; + } + private int? _Ordinal; + public int Ordinal + { + get + { + //int retval = 1; + //for (ItemInfo ii = MyParent; ii != null; ii = ii.MyParent) retval++; + //return retval; + //if (_Ordinal != null) return (int)_Ordinal; // Cache Ordinal + if (MyPrevious != null) return (int)(_Ordinal = MyPrevious.Ordinal + 1); + return (int)(_Ordinal = 1); + } + } + public string CslaType + { get { return this.GetType().FullName; } } + public override string ToString() + { + //Item editable = Item.GetExistingByPrimaryKey(_ItemID); + //return string.Format("{0}{1} {2}", (editable == null ? "" : (editable.IsDirty ? "* " : "")), + // (MyContent.Type >= 20000 ? Ordinal.ToString() + "." : MyContent.Number), MyContent.Text); + ContentInfo cont = MyContent; + string number = cont.Number; + if (cont.Type >= 20000) number = Ordinal.ToString() + "."; + return string.Format("{0} {1}", number, cont.Text); + //return string.Format("{0} {1}", cont.Number, cont.Text); + //return "Now is the time for all good men to come to the aid of their country!"; + } + //public string ToString(string str,System.IFormatProvider ifp) + //{ + // return ToString(); + //} + public string nz(string str, string def) + { + return (str == null ? def : str); + } + public string Path + { + get + { + string number = (MyContent.Type >= 20000 ? Ordinal.ToString() + "." : (nz(MyContent.Number,"")==""? MyContent.Text: MyContent.Number)); + ItemInfo parent = this; + while (parent.MyPrevious != null) parent = parent.MyPrevious; + if (parent.ItemPartCount == 0) + return number + ", " + MyContent.Text; + else + { + PartInfo partInfo = parent.ItemParts[0]; + return partInfo.MyContent.ContentItems.Items[0].Path + " " + ((E_FromType)partInfo.FromType).ToString() + " " + number; + } + } + } + public ContentInfo ParentContent + { + get + { + string number = (MyContent.Type >= 20000 ? Ordinal.ToString() + "." : (nz(MyContent.Number, "") == "" ? MyContent.Text : MyContent.Number)); + ItemInfo parent = this; + while (parent.MyPrevious != null) parent = parent.MyPrevious; + if (parent.ItemPartCount == 0) + return null; + else + { + return parent.ItemParts[0].MyContent; + } + } + } + public ItemInfo MyParent + { + get + { + //if (ItemDocVersionCount > 0) return ItemDocVersions[0]; Need to create one interface to support Folders, DocVersions and Items + ContentInfo parentContent = ParentContent; + if (parentContent == null || parentContent.ContentItemCount == 0) return null; + return parentContent.ContentItems[0]; + } + } + private ItemInfoList Lookup(int fromType, ref ItemInfoList itemInfoList) + { + if (itemInfoList != null) return itemInfoList; + if (MyContent.ContentPartCount != 0) + foreach (PartInfo partInfo in MyContent.ContentParts) + if (partInfo.FromType == fromType) + { + itemInfoList = partInfo._MyItems = ItemInfoList.GetList(partInfo.ItemID,partInfo.FromType); + return itemInfoList; + } + return null; + } + private ItemInfoList _Procedures; + public ItemInfoList Procedures + { get { return Lookup(1,ref _Procedures); } } + private ItemInfoList _Sections; + public ItemInfoList Sections + { get { return Lookup(2,ref _Sections); } } + private ItemInfoList _Cautions; + public ItemInfoList Cautions + { get { return Lookup(3,ref _Cautions); } } + private ItemInfoList _Notes; + public ItemInfoList Notes + { get { return Lookup(4,ref _Notes); } } + private ItemInfoList _RNOs; + public ItemInfoList RNOs + { get { return Lookup(5,ref _RNOs); } } + private ItemInfoList _Steps; + public ItemInfoList Steps + { get { return Lookup(6,ref _Steps); } } + private ItemInfoList _Tables; + public ItemInfoList Tables + { get { return Lookup(7,ref _Tables); } } + //public XmlDocument ToXml() + //{ + // XmlDocument retval = new XmlDocument(); + // retval.LoadXml(""); + // return ToXml(retval.DocumentElement); + //} + //public void AddList(XmlNode xn,string name, ItemInfoList itemInfoList) + //{ + // if (itemInfoList != null) + // { + // XmlNode nd = xn.OwnerDocument.CreateElement(name); + // xn.AppendChild(nd); + // itemInfoList.ToXml(xn); + // } + //} + //public XmlDocument ToXml(XmlNode xn) + //{ + // XmlNode nd = MyContent.ToXml(xn); + // // Now add the children + // AddList(nd, "Procedures", Procedures); + // AddList(nd, "Sections", Sections); + // AddList(nd, "Cautions", Cautions); + // AddList(nd, "Notes", Notes); + // AddList(nd, "RNOs", RNOs); + // AddList(nd, "Steps", SubItems); + // AddList(nd, "Tables", Tables); + // return xn.OwnerDocument; + //} + #region IVEReadOnlyItem + PartInfoList _PartInfoList; + public System.Collections.IList GetChildren() + { + _PartInfoList = this.MyContent.ContentParts; + return _PartInfoList; + } + //public bool ChildrenAreLoaded + //{ + // get { return _PartInfoList == null; } + //} + public bool HasChildren + { + get { return this.MyContent.ContentPartCount > 0; } + } + private IVEDrillDownReadOnly _ActiveParent = null; + public IVEDrillDownReadOnly ActiveParent + { + get + { + if (_ActiveParent == null) + { + if (MyPrevious != null) + _ActiveParent = _MyPrevious.ActiveParent; + else + { + if (ItemDocVersionCount > 0) + _ActiveParent = this.ItemDocVersions[0]; + else + { + ContentInfo parentContent = ParentContent; + if (parentContent == null || parentContent.ContentItemCount == 0) + _ActiveParent = this; + else + _ActiveParent = parentContent.ContentItems[0]; + } + } + } + return _ActiveParent==this ? null : _ActiveParent; + } + //get + //{ + // if (MyPrevious != null) return _MyPrevious.ActiveParent; + // if (ItemDocVersionCount > 0) return ItemDocVersions[0]; + // ContentInfo parentContent = ParentContent; + // if (parentContent == null || parentContent.ContentItemCount == 0) return null; + // return parentContent.ContentItems[0]; + //} + } + private FormatInfo _ActiveFormat = null; + public FormatInfo ActiveFormat + { + get + { + if(_ActiveFormat == null) + _ActiveFormat = (LocalFormat != null ? LocalFormat : ActiveParent.ActiveFormat); + return _ActiveFormat; + } + //get { return LocalFormat != null ? LocalFormat : ActiveParent.ActiveFormat; } + } + public FormatInfo LocalFormat + { + get { return MyContent.MyFormat; } + } + public DynamicTypeDescriptor MyConfig + { + get { return null; } + } + //public bool HasStandardSteps() + //{ return MyContent.ContentItemCount > 1; } + public Color ForeColor + { get { return (HasBrokenRules != null ? Color.Red : (MyContent.ContentItemCount > 1 ? Color.Blue : Color.Black)); } } + public Color BackColor + { get { return (ItemAnnotationCount > 0 ? Color.Yellow : Color.White); } } + #endregion + } + #endregion ItemInfo + #region ItemInfoList + public partial class ItemInfoList + { + //public void ToXml(XmlNode xn) + //{ + // foreach (ItemInfo itemInfo in this) + // { + // itemInfo.ToXml(xn); + // } + //} + public static ItemInfoList GetList(int? itemID,int type) + { + try + { + ItemInfoList tmp = DataPortal.Fetch(new ItemListCriteria(itemID,type)); + ItemInfo.AddList(tmp); + tmp.AddEvents(); + ContentInfoList.GetList(itemID); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ItemInfoList.GetChildren", ex); + } + } + [Serializable()] + private class ItemListCriteria + { + public ItemListCriteria(int? itemID,int type) + { + _ItemID = itemID; + _Type = type; + } + private int? _ItemID; + public int? ItemID + { + get { return _ItemID; } + set { _ItemID = value; } + } + private int _Type; + public int Type + { + get { return _Type; } + set { _Type = value; } + } + } + private void DataPortal_Fetch(ItemListCriteria criteria) + { + this.RaiseListChangedEvents = false; + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "vesp_ListItems"; + cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) + { + ItemInfo itemInfo = null; + switch ((E_FromType)criteria.Type) + { + case E_FromType.Procedure: + itemInfo = new ProcedureInfo(dr); + break; + case E_FromType.Section: + itemInfo = new SectionInfo(dr); + break; + default: + itemInfo = new StepInfo(dr); + break; + } + this.Add(itemInfo); + } + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + Database.LogException("ItemInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + } + #endregion + #region ProcedureInfo + [Serializable()] + public partial class ProcedureInfo : ItemInfo, IVEDrillDownReadOnly + { + public ProcedureInfo(SafeDataReader dr) : base(dr) { } + public new Procedure Get() + { + return (Procedure) (_Editable = Procedure.Get(ItemID)); + } + #region ProcedureConfig + [NonSerialized] + private ProcedureConfig _ProcedureConfig; + public ProcedureConfig ProcedureConfig + { get { return (_ProcedureConfig != null ? _ProcedureConfig : _ProcedureConfig = new ProcedureConfig(this)); } } + #endregion + public new DynamicTypeDescriptor MyConfig + { + get { return ProcedureConfig ; } + } + } + #endregion + #region Procedure + [Serializable()] + public partial class Procedure : Item + { + public new static Procedure Get(int itemID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Item"); + try + { + Procedure tmp = (Procedure)GetExistingByPrimaryKey(itemID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(itemID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") tmp = null; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Item.Get", ex); + } + } + public new Procedure Save() + { + return (Procedure)base.Save(); + } + #region ProcedureConfig + [NonSerialized] + private ProcedureConfig _ProcedureConfig; + public ProcedureConfig ProcedureConfig + { + get + { + if (_ProcedureConfig == null) + { + _ProcedureConfig = new ProcedureConfig(this); + _ProcedureConfig.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(_ProcedureConfig_PropertyChanged); + } + return _ProcedureConfig; + } + } + private void _ProcedureConfig_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) + { + MyContent.Config = _ProcedureConfig.ToString(); + } + #endregion + } + #endregion + #region SectionInfo + [Serializable()] + public partial class SectionInfo : ItemInfo, IVEDrillDownReadOnly + { + public SectionInfo(SafeDataReader dr) : base(dr) { } + public new Section Get() + { + return (Section)(_Editable = Section.Get(ItemID)); + } + #region SectionConfig + [NonSerialized] + private SectionConfig _SectionConfig; + public SectionConfig SectionConfig + { get { return (_SectionConfig != null ? _SectionConfig : _SectionConfig = new SectionConfig(this)); } } + #endregion + public new DynamicTypeDescriptor MyConfig + { + get { return SectionConfig; } + } + } + #endregion + #region Section + [Serializable()] + public partial class Section : Item + { + public new static Section Get(int itemID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Item"); + try + { + Section tmp = (Section)GetExistingByPrimaryKey(itemID); + if (tmp == null) + { + tmp = DataPortal.Fetch
(new PKCriteria(itemID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") tmp = null; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Item.Get", ex); + } + } + + public new Section Save() + { + return (Section)base.Save(); + } + + #region SectionConfig + [NonSerialized] + private SectionConfig _SectionConfig; + public SectionConfig SectionConfig + { + get + { + if (_SectionConfig == null) + { + _SectionConfig = new SectionConfig(this); + _SectionConfig.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(_SectionConfig_PropertyChanged); + } + return _SectionConfig; + } + } + private void _SectionConfig_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) + { + MyContent.Config = _SectionConfig.ToString(); + } + #endregion + } + #endregion + #region StepInfo + [Serializable()] + public partial class StepInfo : ItemInfo + { + //public override string ToString() + //{ + // return "Step " + base.ToString(); + //} + public StepInfo(SafeDataReader dr) : base(dr) { } + public new Step Get() + { + return (Step)(_Editable = Step.Get(ItemID)); + } + //public E_FromType FromType + //{ get { return E_FromType.Step; } } + } + + #endregion + #region Step + [Serializable()] + public partial class Step : Item + { + public new static Step Get(int itemID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Item"); + try + { + Step tmp = (Step)GetExistingByPrimaryKey(itemID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(itemID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") tmp = null; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Item.Get", ex); + } + } + //#region StepConfig + //[NonSerialized] + //private StepConfig _StepConfig; + //public StepConfig StepConfig + //{ + // get + // { + // if (_StepConfig == null) + // { + // _StepConfig = new StepConfig(this); + // _StepConfig.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(_StepConfig_PropertyChanged); + // } + // return _SectionConfig; + // } + //} + //private void _StepConfig_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) + //{ + // MyContent.Config = _StepConfig.ToString(); + //} + //#endregion + } + #endregion +} diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/PartExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/PartExt.cs new file mode 100644 index 00000000..38b8abaf --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Extension/PartExt.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Csla; +using Csla.Data; + +namespace VEPROMS.CSLA.Library +{ + public partial class ContentPart + { + public override string ToString() + { + return string.Format("{0} {1}", MyItem.MyContent.Number, MyItem.MyContent.Text); + } + } + public partial class ItemPart + { + public override string ToString() + { + return string.Format("{0} {1}", _MyContent.Number, MyContent.Text); + } + } + public partial class Part + { + public override string ToString() + { + return string.Format("{0} {1}", MyItem.MyContent.Number, MyItem.MyContent.Text); + } + } + public partial class PartInfo : IVEDrillDownReadOnly + { + public E_FromType PartType + { get { return (E_FromType)_FromType; } } + public E_FromTypes PartTypes + { get { return (E_FromTypes)_FromType; } } + public override string ToString() + { + return string.Format("{0}", PartTypes); + } + //public string ToString(string str, System.IFormatProvider ifp) + //{ + // return ToString(); + //} + #region IVEDrillDownReadOnly + public ItemInfoList _MyItems; + public ItemInfoList MyItems + { get { return (_MyItems != null? _MyItems : _MyItems = ItemInfoList.GetList(_ItemID,_FromType)); } } + public System.Collections.IList GetChildren() + { + return (_MyItems != null ? _MyItems : _MyItems = ItemInfoList.GetList(_ItemID, _FromType)); + } + //public bool ChildrenAreLoaded + //{ + // get { return _MyItems == null; } + //} + public bool HasChildren + { + get { return this.MyContent.ContentPartCount > 0; } + } + public IVEDrillDownReadOnly ActiveParent + { + get + { + ContentInfo parentContent = MyContent; + if (parentContent == null || parentContent.ContentItemCount == 0) return null; + return parentContent.ContentItems[0]; + } + } + public FormatInfo ActiveFormat + { + get { return ActiveParent.ActiveFormat; } + } + public FormatInfo LocalFormat + { + get { return null; } + } + public DynamicTypeDescriptor MyConfig + { + get { return null; } + } + //public bool HasStandardSteps() + //{ return false; } + #endregion + } + public enum E_FromType : int + { + Procedure = 1, Section = 2, Caution = 3, Note = 4, RNO = 5, Step = 6, Table = 7 + } + public enum E_FromTypes : int + { + Procedures = 1, Sections = 2, Cautions = 3, Notes = 4, RNOs = 5, Steps = 6, Tables = 7 + } +} diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/PropertyDescriptors.cs b/PROMS/VEPROMS.CSLA.Library/Extension/PropertyDescriptors.cs new file mode 100644 index 00000000..c92d4210 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Extension/PropertyDescriptors.cs @@ -0,0 +1,95 @@ +// ======================================================================== +// Copyright 2006 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +using System.Collections; + +namespace VEPROMS.CSLA.Library +{ + public partial class ChildFoldersPropertyDescriptor + { + public override string DisplayName + { get { return Item.Name; } } + public override string Description + { get { return Item.Title; } } + public override string Name + { get { return Item.Name; } } + } + public partial class FolderDocVersionsPropertyDescriptor + { + public override string DisplayName + { get { return Item.Name; } } + public override string Description + { get { return Item.Name; } } + public override string Name + { get { return Item.Name; } } + } + public class FormatList : System.ComponentModel.StringConverter + { + private static SortedList _FormatInfoList; + private static void LoadSortedList() + { + if (_FormatInfoList == null) + { + _FormatInfoList = new SortedList(); + foreach (FormatInfo formatInfo in FormatInfoList.Get()) + { + _FormatInfoList.Add(formatInfo.Name, formatInfo); + } + _FormatInfoList.Add("", null); + } + } + public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) + { + LoadSortedList(); + return new StandardValuesCollection((ICollection)_FormatInfoList.Values); + } + public override bool GetStandardValuesSupported(ITypeDescriptorContext context) + { + return true; + } + public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) + { + return true; + } + public static int? ToInt(string formatName) + { + if (formatName == null || formatName == string.Empty) return null; + LoadSortedList(); + foreach (FormatInfo formatInfo in _FormatInfoList.Values) + if (formatInfo != null && formatInfo.Name == formatName) return formatInfo.FormatID; + return null; + } + public static string ToString(int? formatID) + { + if (formatID == null) return null; + LoadSortedList(); + foreach (FormatInfo formatInfo in _FormatInfoList.Values) + if (formatInfo != null && formatInfo.FormatID == formatID) return formatInfo.ToString(); + return null; + } + public static Format ToFormat(string formatName) + { + if (formatName == null || formatName == string.Empty) return null; + LoadSortedList(); + foreach (FormatInfo formatInfo in _FormatInfoList.Values) + if (formatInfo != null && formatInfo.ToString() == formatName) return formatInfo.Get(); + return null; + } + } +} diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/TransitionExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/TransitionExt.cs new file mode 100644 index 00000000..679f6ce6 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Extension/TransitionExt.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace VEPROMS.CSLA.Library +{ + public partial class TransitionInfo + { + public string PathTo + { + get + { + //return "To " + MyItemToID.Path; + return MyItemToID.Path; + } + } + public string PathFrom + { + get + { + //return "From " + MyContent.ContentItems[0].Path; + return MyContent.ContentItems[0].Path; + } + } + } +} diff --git a/PROMS/VEPROMS.CSLA.Library/Format/DocStyles.cs b/PROMS/VEPROMS.CSLA.Library/Format/DocStyles.cs new file mode 100644 index 00000000..af372a76 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Format/DocStyles.cs @@ -0,0 +1,483 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.ComponentModel; +using System.Xml; + +namespace VEPROMS.CSLA.Library +{ + #region DocStyles + [TypeConverter(typeof(ExpandableObjectConverter))] + public class DocStyles : vlnFormatItem + { + [Description("Document Styles Name")] + private LazyLoad _Name; + public string Name + { + get + { + return LazyLoad(ref _Name, "@Name"); + } + } + private DocStyleList _DocStyleList; + public DocStyleList DocStyleList + { + get + { + return (_DocStyleList == null) ? _DocStyleList = new DocStyleList(SelectNodes("DocStyle")): _DocStyleList; + } + set { _DocStyleList = value; } + } + public DocStyles(XmlNode xmlNode) : base(xmlNode) { } + } + #endregion + #region DocStyleAll + #region DocStyle + [TypeConverter(typeof(ExpandableObjectConverter))] + public class DocStyle : vlnFormatItem + { + public DocStyle(XmlNode xmlNode) : base(xmlNode) { } + public DocStyle() : base() { } + #region IndexName + private LazyLoad _Index; + public int? Index + { + get + { + return LazyLoad(ref _Index, "@Index"); + } + } + [Description("Document Styles Name")] + private LazyLoad _Name; + public string Name + { + get + { + return LazyLoad(ref _Name, "@Name"); + } + } + #endregion + #region Font + private VE_Font _Font; + [Category("Font")] + [DisplayName("Font")] + [Description("Font")] + public VE_Font Font + { + get + { + return(_Font == null) ?_Font = new VE_Font(XmlNode): _Font; + } + } + #endregion + #region numberingsequence + [Category("Miscellaneous")] + [Description("Numbering Sequence")] + private LazyLoad _NumberingSequence; + public E_NumberingSequence? NumberingSequence + { + get + { + return LazyLoad(ref _NumberingSequence, "@NumberingSequence"); + } + } + #endregion + #region Oldtonew + [Category("Miscellaneous")] + [Description("Convert from old to new")] + private LazyLoad _OldToNew; + public int? OldToNew + { + get + { + return LazyLoad(ref _OldToNew, "@OldToNew"); + } + } + #endregion + #region pagestyle + private PageStyle _pagestyle; + [Category("Miscellaneous")] + [DisplayName("Page Style")] + [Description("Page Style")] + public PageStyle pagestyle + { + get + { + string str = "//PageStyles/PageStyle[" + (IntLookup("@PageStyle") + 1).ToString() + "]"; + XmlNode xn = SelectSingleNode(str); + if (_pagestyle == null) _pagestyle = new PageStyle(SelectSingleNode("//PageStyles/PageStyle[" + (IntLookup("@PageStyle") + 1).ToString() + "]")); + return _pagestyle; + } + } + #endregion + #region SubElements + private Layout _Layout; + public Layout Layout + { + get + { + return (_Layout == null ? _Layout = new Layout(SelectSingleNode("Layout")) : _Layout); + } + } + private Continue _Continue; + public Continue Continue + { + get + { + return (_Continue == null ? _Continue = new Continue(SelectSingleNode("Continue")) : _Continue); + } + } + private End _End; + public End End + { + get + { + return (_End == null ? _End = new End(SelectSingleNode("End")) : _End); + } + } + private Final _Final; + public Final Final + { + get + { + return (_Final == null ? _Final = new Final(SelectSingleNode("Final")) : _Final); + } + } + private StructureStyle _StructureStyle; + public StructureStyle StructureStyle + { + get + { + return (_StructureStyle == null ? _StructureStyle = new StructureStyle(SelectSingleNode("StructureStyle")) : _StructureStyle); + } + } + #endregion + public override string ToString() + { + return String.Format("{0:D2} - {1}", Index, Name); + } + } + #endregion + #region DocStyleList + [TypeConverter(typeof(vlnListConverter))] + public class DocStyleList : vlnFormatList + { + public DocStyleList(XmlNodeList xmlNodeList) : base(xmlNodeList) { } + } + #endregion + #region Layout + [TypeConverter(typeof(ExpandableObjectConverter))] + public class Layout : vlnFormatItem + { + public Layout(XmlNode xmlNode) : base(xmlNode) { } + public Layout() : base() { } + #region TopRow + private LazyLoad _TopRow; + [Category("Layout")] + [DisplayName("Top Row on Printed Page")] + [Description("Top Row on Printed Page")] + public int? TopRow + { + get + { + return LazyLoad(ref _TopRow, "@TopRow"); + } + } + #endregion + #region FooterLength + private LazyLoad _FooterLength; + [Category("Location")] + [DisplayName("Number of lines required for footer")] + [Description("Number of lines required for footer")] + public int? FooterLength + { + get + { + return LazyLoad(ref _FooterLength, "@FooterLength"); + } + } + #endregion + #region LeftMargin + private LazyLoad _LeftMargin; + [Category("Location")] + [DisplayName("Size of left margin")] + [Description("Size of left margin")] + public int? LeftMargin + { + get + { + return LazyLoad(ref _LeftMargin, "@LeftMargin"); + } + } + #endregion + #region PageLength + private LazyLoad _PageLength; + [Category("Location")] + [DisplayName("Length of Page")] + [Description("Length of Page")] + public int? PageLength + { + get + { + return LazyLoad(ref _PageLength, "@PageLength"); + } + } + #endregion + #region PageWidth + private LazyLoad _PageWidth; + [Category("Location")] + [DisplayName("Width of Page")] + [Description("Width of Page")] + public int? PageWidth + { + get + { + return LazyLoad(ref _PageWidth, "@PageWidth"); + } + } + #endregion + } + #endregion + #region ContinueAll + #region Continue + [TypeConverter(typeof(ExpandableObjectConverter))] + public class Continue : vlnFormatItem + { + public Continue(XmlNode xmlNode) : base(xmlNode) { } + public Continue() : base() { } + #region Font + private VE_Font _Font; + [Category("Continue Msg")] + [DisplayName("Font")] + [Description("Font")] + public VE_Font Font + { + get + { + return (_Font == null ? _Font = new VE_Font(base.XmlNode) : _Font); + } + } + #endregion + #region SubElements + private Top _Top; + public Top Top + { + get + { + return (_Top == null? _Top = new Top(SelectSingleNode("Top")): _Top); + } + } + private Bottom _Bottom; + public Bottom Bottom + { + get + { + return (_Bottom == null ? _Bottom = new Bottom(SelectSingleNode("Bottom")) : _Bottom); + } + } + #endregion + } + #endregion + #region Top + [TypeConverter(typeof(ExpandableObjectConverter))] + public class Top : vlnFormatItem + { + public Top(XmlNode xmlNode) : base(xmlNode) { } + public Top() : base() { } + #region Margin + private LazyLoad _Margin; + [Category("Continue Msg")] + [DisplayName("Margin for top msg")] + [Description("Margin for top msg")] + public int? Margin + { + get + { + return LazyLoad(ref _Margin, "@Margin"); + } + } + #endregion + #region HLS + private LazyLoad _HLS; + [Category("Continue Msg")] + [DisplayName("Include HLS in top continue msg")] + [Description("Include HLS in top continue msg")] + public int? HLS + { + get + { + return LazyLoad(ref _HLS, "@HLS"); + } + } + #endregion + #region Message + private LazyLoad _Message; + [Category("Continue Msg")] + [DisplayName("Top Continue Msg")] + [Description("Top Continue Msg")] + public string Message + { + get + { + return LazyLoad(ref _Message, "@Message"); + } + } + #endregion + } + #endregion + #region Bottom + [TypeConverter(typeof(ExpandableObjectConverter))] + public class Bottom : vlnFormatItem + { + public Bottom(XmlNode xmlNode) : base(xmlNode) { } + public Bottom() : base() { } + #region Margin + private LazyLoad _Margin; + [Category("Continue Msg")] + [DisplayName("Margin for bottom msg")] + [Description("Margin for bottom msg")] + public int? Margin + { + get + { + return LazyLoad(ref _Margin, "@Margin"); + } + } + #endregion + #region Location + [Category("Continue Msg")] + [Description("Bottom Continue Location")] + + private LazyLoad _NumberingSequence; + public E_NumberingSequence? NumberingSequence + { + get + { + return LazyLoad(ref _NumberingSequence, "@NumberingSequence"); + } + } + private LazyLoad _Location; + public E_ContBottomLoc? Location + { + get + { + return LazyLoad(ref _Location, "@Location"); + } + } + #endregion + #region Message + private LazyLoad _Message; + [Category("Continue Msg")] + [DisplayName("Bottom Continue Msg")] + [Description("Bottom Continue Msg")] + public string Message + { + get + { + return LazyLoad(ref _Message, "@Message"); + } + } + #endregion + } + #endregion + #endregion + #region End + [TypeConverter(typeof(ExpandableObjectConverter))] + public class End : vlnFormatItem + { + public End(XmlNode xmlNode) : base(xmlNode) { } + public End() : base() { } + #region Font + private VE_Font _Font; + [Category("End Msg")] + [DisplayName("Font")] + [Description("Font")] + public VE_Font Font + { + get + { + return (_Font == null ? _Font = new VE_Font(XmlNode) : _Font); + } + } + #endregion + #region Flag + private LazyLoad _Flag; + [Category("End Msg")] + [DisplayName("End Msg Exists")] + [Description("End Msg Exists")] + public int? Flag + { + get + { + return LazyLoad(ref _Flag, "@Flag"); + } + } + #endregion + #region Message + private LazyLoad _Message; + [Category("End Msg")] + [DisplayName("End Message")] + [Description("End Message")] + public string Message + { + get + { + return LazyLoad(ref _Message, "@Message"); + } + } + #endregion + } + #endregion + #region Final + [TypeConverter(typeof(ExpandableObjectConverter))] + public class Final : vlnFormatItem + { + public Final(XmlNode xmlNode) : base(xmlNode) { } + public Final() : base() { } + private LazyLoad _Message; + [Category("Final Msg")] + [DisplayName("Final Message")] + [Description("Final Message")] + public string Message + { + get + { + return LazyLoad(ref _Message, "@Message"); + } + } + } + #endregion + #region StructureStyle + [TypeConverter(typeof(ExpandableObjectConverter))] + public class StructureStyle : vlnFormatItem + { + public StructureStyle(XmlNode xmlNode) : base(xmlNode) { } + public StructureStyle() : base() { } + #region Where + [Category("Structure Style")] + [Description("Where Used")] + private LazyLoad _Where; + public E_DocStyleUse? Where + { + get + { + return LazyLoad(ref _Where, "@Where"); + } + } + #endregion + #region Style + [Category("Structure Style")] + [Description("Style")] + private LazyLoad _Style; + public E_DocStructStyle? Style + { + get + { + return LazyLoad(ref _Style, "@Style"); + } + } + #endregion + } + #endregion + #endregion +} diff --git a/PROMS/VEPROMS.CSLA.Library/Format/ENums.cs b/PROMS/VEPROMS.CSLA.Library/Format/ENums.cs new file mode 100644 index 00000000..5add3817 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Format/ENums.cs @@ -0,0 +1,199 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.ComponentModel; + +namespace VEPROMS.CSLA.Library +{ + #region ENums + [Flags] + public enum E_PurchaseOptions : uint + { + APPROVEONE = 0x0001, + ACCPAGINATION = 0x0002, + LIBMAINT = 0x0004, + TRANSFER = 0x0008, + STREES = 0x0010, + DATECHGSUMRPT = 0x0020, + SETPOINTUSAGE = 0x0040, + REPLACE = 0x0080, + FLOPPYTRANSFER = 0x0100, + APPROVEGENERICBACK = 0x0200, + DISTRIBUTEAPPROVED = 0x0400, + OUTSIDETRANSITIONS = 0x0800, + ENHANCEDBACKGROUNDS = 0x1000, + ENHANCEDDEVIATIONS = 0x2000, + AUTOTABLEOFCONTENTS = 0x4000, + AUTOPLACEKEEPER = 0x8000 + } + [Flags] + public enum E_Style : uint + { + // Fonts removed, not used here. + NONE = 0, + UNDERLINE = 64, BOLD = 128, LANDSCAPE = 256, ITALICS = 512, BOXED = 1024, BOXELEMENT = 0x00000800, + TBCENTERED = 4096, RTCHECKOFF = 8192, LTCHECKOFF = 16384, BIGSCRIPT = 32768, HLTEXTHL = 65536, + RTCHECKOFFWITHASTERISK = 131072, DB_UNDERLINE = 262144, COLDOTS = 524288, + MMBOLD = 1048576, RIGHTJUSTIFY = 2097152, SUBSCRIPT = 4194304, SUPERSCRIPT = 8388608, + PAGELISTITEM = 16777216, PRINTONTOPOFLINE = 33554432, HORZCENTER = 67108864, + CIRCLESTRING2 = 0x08000000, ALIGNWITHUP1 = 0x10000000, ALIGNWSECNUM = 0x20000000, + MATCHCOLUMNMODE = 0x40000000, KEEPRNOSUBSTYLE = 0x80000000 + }; + public enum E_ChangeBarMessage : uint + { + DATEANDUSERID = 0, + REVNUMBER = 1, + USERID = 2, + NOTHING = 3 + } + public enum E_EMode : uint + { + INSERT = 0, + OVERRIDE = 1 + } + public enum E_ViewMode : uint + { + VIEW = 0, + EDIT = 1 + } + public enum E_EditPrintMode : uint + { + EDIT = 0, + PRINT = 1 + } + [Flags] + public enum E_Justify : uint + { + PSCENTER = 0, // Page style, center field + PSLEFT = 1, // Page style, left justify + PSRIGHT = 2, // Page style, right justify + // *** PS modifiers: *** + PSBOTTOM = 4, // Page style, always use bottom half line + PSTOP = 8, // Page style, always use top half line + PSTRUE = 16, // page style, don't adjust per CPI* (not needed after 4.0) + PSNOTFIRST = 32, // page style, don't put this token on the first page of section + PSONLYFIRST = 64, // page style, only put this token on the first page of section + PSRELROW = 128, // place in RelPageList + PSNOHALFLINE = 256, // DontDoHalflines for his paglist row item + PSNOTLAST = 0x200, // 512 - use this token on all but the last page of this section + PSRTFONLY = 0x400, // Only use this token when the driver is rtf + PSRTFNOT = 0x800, // Do NOT use token when driver is rtf + PSGDIONLY = 0X1000, // Only use this token when the driver is GDI + PSGDINOT = 0x2000, // Do NOT use token when driver is GDI + PSADJBNGROW = 0x4000 // If the pagelist item exceeds the row it's printed on, + // then adjust the starting row for the procedure body + }; + public enum E_NumberingSequence : uint + { + NOPAGENUM = 0, + INCLUDEWOTHSTEPS = 1, + WITHINSECTIONS = 2, + WITHINACCESSORY = 3 + }; + public enum E_ContBottomLoc : uint + { + ENDOFTEXT = 0, + BTWNTEXTANDBOTTOM = 1, + BOTTOMOFPAGE = 2 + }; + [Flags] + public enum E_DocStructStyle : uint + { + //USEONALLPAGES = 0, // Default + //USEONFIRSTPAGE = 1, // Use only on the first page + //USEONALLBUTFIRSTPAGE = 2, // Use on all but the first page + //USEONLASTPAGE = 4, // NO LOGIC exists for this selection. Use only on the last page + NONE = 0, + USESECTIONFOLDOUT = 8, // Attach section foldouts (only active if using SectionLevelFoldouts_ON + DONTCOUNTFOLDOUTPGS = 16, // Used with the USESECTIONFOLDOUT flag. Keeps foldout pages from + // being included in the section total page count. + TABLEOFCONTENTS = 32, + DONTCOUNTINTABOFCONT = 64, + PLACEKEEPER = 128, + ALIGN1STLEVSUBWHLS = 0x00000100, // guess? + DOUBLEBOXHLS = 0x00000200, + USEALTCNTRLINE = 0x00000400, + DONTNUMBERINTOC = 0x00000800, // Don't include page number for this section in the Table of Contents + USESPECIALFIGFRAME = 0x00001000, // for use with stp55 and 55a in bge + HLSUSELETTERS = 0x00002000, // docstyles with this bit set in the DocStructStyle will + // default to using letters for HLSteps + NOSECTIONINSTEPCONTINUE = 0x00004000, // don't include the section number in the step continue + BOTTOMSECTIONCONTINUE = 0x00008000, // print the continue message if the section continues + ALWAYSDOTSTEP = 0x00010000, // put the period after step number in the continue message + XBLANKW1STLEVSUB = 0x00020000, // insert an extra blank line before a 1st level substep + AFFECTEDPAGES = 0x00040000, + DSS_TREATASTRUESECTNUM = 0x00080000, // in conjunction with tietabtolevel, takes section number + // from the last space and appends a period + SAMPLEWATERMARK = 0x00100000, // Will force "SAMPLE" to be printed across the page + // on all pages in this section + DSS_PAGEBREAKHLS = 0x00200000, // Page Breaks on all high level steps + DSS_NOCHKIFCONTTYPEHIGH = 0x00400000, // Will suppress the checkoff if type is HIGH and the + // step is continued on the next page + DSS_WIDTHOVRDSTDHLS = 0x00800000, // Width Override for Standard HLStep in this section + DSS_ADDDOTZEROSTDHLS = 0x01000000, // Append .0 to the Standard HLStep for this section + DSS_SECTIONCOMPRESS = 0x02000000, // Compress all the steps of this section (i.e. use 7 LPI) + DSS_PRINTSECTONFIRST = 0x04000000, // Prints section title/number only on the first + // page of an attachment section, assuming numberingsequence is not 1 + DSS_UNNUMLIKEROMAN = 0x08000000, // the substeps underneath unnumbered HLSteps will have same tabs as romans + DSS_DONTCHANGEROMANLEVEL = 0x10000000, // Dont alter the the substep level for roman-numeral-tabbed hlsteps + DSS_SKIPTWOSTEPLEVELS = 0x20000000, // Skip two step levels for this doc style + DSS_SKIPONESTEPLEVEL = 0x40000000, // Skip one step level for this doc style + DSS_SIMPLETOPSECTIONCONTINUE = 0x80000000, // Use the Top continue message as the section continue */ + }; + public enum E_DocStyleUse : uint + { + USEONALLPAGES = 0, USEONFIRSTPAGE = 1, USEONALLBUTFIRSTPAGE = 2, USEONLASTPAGE = 4 + }; + [Flags] + // acceptence list for adding Tables, Cautions, Notes, Substeps, Next, Previous and RNO + public enum E_AccStep : uint + { + ADDING_CAUTION = 1, + ADDING_NOTE = 2, + ADDING_RNO = 4, + ADDING_SUB = 8, + ADDING_TABLE = 16, + ADDING_NEXT = 32, + ADDING_PREV = 64 + } + [Flags] + public enum E_ReplaceFlags : uint + { + // Generally used: HIGH, RNO, CAUTION, NOTE, TABLE, SUBSTEP, ATTACH + // ANONOP: BKGD, TOC, INSECTITLE, TRAN + // BGEEOP: BKGD, PLACKEEP, TOC, PARTIALS + // CAL1 & WCN & WEP (various): STATTREE, HLSSETPNT + // CAL2 & CPL: SETPOINT + // HLP: CASEINSENS + // CPLSSD: DIFFUNIT, TOC, STATTREE, HLSSETPNT + // CWE: CASEINSENS, DIFFUNIT + // MYA: CASEINSENSALL + HIGH = 0x0001, // Do ReplaceWords in HIGH LEVEL STEPS + RNO = 0x0002, // Do ReplaceWords in RNOS + CAUTION = 0x0004, // Do ReplaceWords in CAUTIONS + NOTE = 0x0008, // Do ReplaceWords in NOTES + TABLE = 0x0010, // Do ReplaceWords in TABLES + SUBSTEP = 0x0020, // Do ReplaceWords in SUBSTEPS + ATTACH = 0x0040, // Do ReplaceWords in ATTACHMENTS + BKGD = 0x0080, // Do ReplaceWords in BACKGROUNDS + DIFFUNIT = 0x0100, // Do ReplaceWords ONLY for different UNIT # + TOC = 0x0200, // Do in auto table-of-contents + STATTREE = 0x0400, + HLSSETPNT = 0x0800, // Do ReplaceWords in HighLevelStep SETPoiNTs + TRAN = 0x1000, // Do ReplaceWords in TRANSITIONS + SETPOINT = 0x2000, // Do ReplaceWords in SETPOINTS + + // Case Sensitivity Flags - default is off (Case Sensitive Replace) + CASEINSENS = 0x0000C000, // Do ReplaceWords for all words thatmatch, regardless of case, + // and replace with the ReplaceWith string as is + CASEINSENSFIRST = 0x4000, // Do ReplaceWords for all words thatexactly match the ReplaceWord, + // except the case of the first character may be different + CASEINSENSALL = 0x8000, // Do ReplaceWords for all words that match the ReplaceWord, regardless of case + + PARTIALS = 0x10000, // Do replace even on partial matches + PLACKEEP = 0x20000, // Do replace in PlaceKeepers + INSECTITLE = 0x40000 + } + #endregion +} diff --git a/PROMS/VEPROMS.CSLA.Library/Format/PageStyles.cs b/PROMS/VEPROMS.CSLA.Library/Format/PageStyles.cs new file mode 100644 index 00000000..6caab392 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Format/PageStyles.cs @@ -0,0 +1,140 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.ComponentModel; +using System.Xml; + +namespace VEPROMS.CSLA.Library +{ + #region PageStyles + [TypeConverter(typeof(vlnListConverter))] + public class PageStyles : vlnFormatList + { + public PageStyles(XmlNodeList xmlNodeList) : base(xmlNodeList) { } + } + #endregion + #region PageStyle + public class PageStyle : vlnFormatItem + { + #region Constructor + public PageStyle(XmlNode xmlNode) : base(xmlNode) { } + public PageStyle() : base() { } + #endregion + #region Business Methods + private LazyLoad _Name; + [DisplayName("Name")] + [Description("Page Style Name")] + public string Name + { + get + { + return LazyLoad(ref _Name, "@Name"); + } + } + private LazyLoad _Index; + [DisplayName("Index")] + [Description("Page Style Index")] + public int? Index + { + get + { + return LazyLoad(ref _Index, "@Index"); + } + } + private PageItems _PageItems; + public PageItems PageItems + { + get + { + return (_PageItems == null)? _PageItems = new PageItems(SelectNodes("Item")): _PageItems; + } + } + #endregion + #region Override ToString + public override string ToString() + { + return string.Format("{0:D2} - {1}", Index, Name); + } + #endregion + } + #endregion + #region PageItems + [TypeConverter(typeof(vlnListConverter))] + public class PageItems : vlnFormatList + { + public PageItems(XmlNodeList xmlNodeList) : base(xmlNodeList) { } + } + #endregion + #region PageItem + public class PageItem : vlnFormatItem + { + #region Constructor + public PageItem(XmlNode xmlNode) : base(xmlNode) { } + public PageItem() : base() { } + #endregion + #region Business Methods + private VE_Font _Font; + [Category("Font")] + [DisplayName("Font")] + [Description("Font")] + public VE_Font Font + { + get + { + return (_Font == null) ?_Font = new VE_Font(XmlNode): _Font; + } + } + private LazyLoad _Token; + [Category("Content")] + [DisplayName("Content")] + [Description("Item Content")] + public string Token + { + get + { + return LazyLoad(ref _Token, "@Token"); + } + } + private LazyLoad _Row; + [Category("Location")] + [DisplayName("Vertical Position")] + [Description("Vertical Position")] + public int? Row + { + get + { + return LazyLoad(ref _Row, "@Row"); + } + } + private LazyLoad _Col; + [Category("Location")] + [DisplayName("Horizontal Position")] + [Description("Horizontal Position")] + public int? Col + { + get + { + return LazyLoad(ref _Col, "@Col"); + } + } + private LazyLoad _Justify; + public E_Justify? Justify + { + get + { + return LazyLoad(ref _Justify, "@Justify"); + } + } + #endregion + #region Override ToString + public override string ToString() + { + //return string.Format("({0:D5},{1:D5}) - {2}",Row,Col,Token); + return Token; + } + public override string GetPDDisplayName() + { return string.Format("({0},{1})",Row,Col); } + #endregion + } + #endregion +} diff --git a/PROMS/VEPROMS.CSLA.Library/Format/PlantFormat.cs b/PROMS/VEPROMS.CSLA.Library/Format/PlantFormat.cs new file mode 100644 index 00000000..d56b1f35 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Format/PlantFormat.cs @@ -0,0 +1,2642 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.ComponentModel; +using System.Drawing; + +namespace VEPROMS.CSLA.Library +{ + #region PlantFormat + [TypeConverter(typeof(ExpandableObjectConverter))] + public class PlantFormat + { + public PlantFormat(Format format) + { + _MyFormat = format; + } + private Format _MyFormat; + public Format MyFormat + { + get { return _MyFormat; } + set { _MyFormat = value; } + } + private vlnFormatDocument _XmlDoc; + internal vlnFormatDocument XmlDoc + { + get + { + if (_XmlDoc == null) + _XmlDoc = new vlnFormatDocument(_MyFormat); + return _XmlDoc; + } + } + private FormatData _FormatData; + public FormatData FormatData + { + get + { + if (_FormatData == null) _FormatData = new FormatData(XmlDoc.SelectSingleNode("/PlantFormat/FormatData")); + return _FormatData; + } + } + private PageStyles _PageStyles; + public PageStyles PageStyles + { + get + { + if (_PageStyles == null) _PageStyles = new PageStyles(XmlDoc.SelectNodes("/PlantFormat/PageStyles/PageStyle")); + return _PageStyles; + } + } + private DocStyles _DocStyles; + public DocStyles DocStyles + { + get + { + if (_DocStyles == null) _DocStyles = new DocStyles(XmlDoc.SelectSingleNode("/PlantFormat/DocStyles")); + return _DocStyles; + } + } + } + #endregion + #region VE_Font + [TypeConverter(typeof(ExpandableObjectConverter))] + public class VE_Font : vlnFormatItem + { + public VE_Font(XmlNode xmlNode) : base(xmlNode) { } + private LazyLoad _Family; + private Font _WindowsFont; + public Font WindowsFont + { + get + { + // TODO: eventually want styles + // TODO: Size should be float to support 10.5 etc. + if (_WindowsFont == null) _WindowsFont = new Font(Family, (float)Size); + return _WindowsFont; + } + } + [Description("Font Family")] + public string Family + { + get + { + return LazyLoad(ref _Family,"Font/@Family"); + } + } + private LazyLoad _Size; + [Description("Font Size (in Double Points)")] + public int? Size + { + get + { + return LazyLoad(ref _Size, "Font/@Size"); + } + } + private LazyLoad _Style; + public E_Style? Style + { + get + { + return LazyLoad(ref _Style, "Font/@Style"); + } + } + public override string ToString() + { + return string.Format("{0}, {1} pt, {2}", Family, Size, Style); + } + } + #endregion + #region FormatData + [TypeConverter(typeof(ExpandableObjectConverter))] + public class FormatData : vlnFormatItem + { + public FormatData(XmlNode xmlNode) : base(xmlNode) { } + private LazyLoad _Name; + public string Name + { + get + { + return LazyLoad(ref _Name, "@Name"); + } + } + private LazyLoad _XtraFlags; + public string XtraFlags + { + get + { + return LazyLoad(ref _XtraFlags, "XtraFlags"); + } + } + public bool XtraOptions(string attr) + { + XmlNode nd = this.SelectSingleNode("XtraFlags/@" + attr); + if (nd == null) return false; + if (nd.InnerText.ToUpper() == "TRUE") return true; + return false; + } + private LazyLoad _PurchaseOptions; + public E_PurchaseOptions? PurchaseOptions + { + get + { + return LazyLoad(ref _PurchaseOptions, "@PurchaseOptions"); + } + } + private VE_Font _Font; + public VE_Font Font + { + get + { + return _Font == null? _Font = new VE_Font(base.XmlNode): _Font; + } + } + private EditData _EditData; + public EditData EditData + { + get + { + return _EditData == null ? _EditData = new EditData(SelectSingleNode("EditData")): _EditData; + } + } + private PrintData _PrintData; + public PrintData PrintData + { + get + { + return _PrintData == null? _PrintData = new PrintData(SelectSingleNode("PrintData")):_PrintData; + } + } + private ProcData _ProcData; + public ProcData ProcData + { + get + { + return _ProcData == null? _ProcData = new ProcData(SelectSingleNode("ProcData")):_ProcData; + } + } + private SectData _SectData; + public SectData SectData + { + get + { + return _SectData == null? _SectData = new SectData(SelectSingleNode("SectData")):_SectData; + } + } + private BoxList _BoxList; + public BoxList BoxList + { + get + { + return _BoxList == null? _BoxList = new BoxList(SelectNodes("BoxData/Box")):_BoxList; + } + set { _BoxList = value; } + } + private TransData _TransData; + public TransData TransData + { + get + { + return _TransData == null? _TransData = new TransData(SelectSingleNode("TransData")):_TransData; + } + } + private StepDataList _StepDataList; + public StepDataList StepDataList + { + get + { + return _StepDataList == null? _StepDataList = new StepDataList(SelectNodes("StepData/Step")):_StepDataList; + } + set { _StepDataList = value; } + } + } + #endregion + #region EditData + [TypeConverter(typeof(ExpandableObjectConverter))] + public class EditData : vlnFormatItem + { + public EditData(XmlNode xmlNode) : base(xmlNode) { } + private LazyLoad _EMode; + public E_EMode? EMode + { + get + { + return LazyLoad(ref _EMode, "@EMode"); + } + } + } + #endregion + #region PrintDataAll + #region PrintData + [TypeConverter(typeof(ExpandableObjectConverter))] + public class PrintData : vlnFormatItem + { + public PrintData(XmlNode xmlNode) : base(xmlNode) { } + private VersionIdTextList _VersionIdTextList; + public VersionIdTextList VersionIdTextList + { + get + { + return _VersionIdTextList == null? _VersionIdTextList = new VersionIdTextList(SelectNodes("VersionIdText/string")):_VersionIdTextList; + } + set { _VersionIdTextList = value; } + } + private ProcDescrList _ProcDescrList; + public ProcDescrList ProcDescrList + { + get + { + return _ProcDescrList == null? _ProcDescrList = new ProcDescrList(SelectNodes("ProcDescrList/ProcDescr")):_ProcDescrList; + } + } + private LazyLoad _DoPrnDrvrAdjusts; + public int? DoPrnDrvrAdjusts + { + get + { + return LazyLoad(ref _DoPrnDrvrAdjusts, "@DoPrnDrvrAdjusts"); + } + } + private LazyLoad _TopOfPageThing; + public string TopOfPageThing + { + get + { + return LazyLoad(ref _TopOfPageThing, "@TopOfPageThing"); + } + } + } + #endregion + #region VersionIdText + [TypeConverter(typeof(ExpandableObjectConverter))] + public class VersionIdText : vlnFormatItem + { + public VersionIdText(XmlNode xmlNode) : base(xmlNode) { } + public VersionIdText() : base() { } + private LazyLoad _Text; + public string Text + { + get + { + return LazyLoad(ref _Text, "text()"); + } + } + public override string GetPDDisplayName() + { return "Text"; } + public override string GetPDDescription() + { return string.Format("VersionIdText '{0}'", Text); } + public override string GetPDCategory() + { return "Version Id Text"; } + public override string ToString() + { + return Text; + } + } + #endregion + #region VersionIdTextList + [TypeConverter(typeof(vlnListConverter))] + public class VersionIdTextList : vlnFormatList + { + public VersionIdTextList(XmlNodeList xmlNodeList) : base(xmlNodeList) { } + } + #endregion + #region ProcDescr + [TypeConverter(typeof(ExpandableObjectConverter))] + public partial class ProcDescr : vlnFormatItem //: BusinessBase, IDisposable + { + public ProcDescr(XmlNode xmlNode) : base(xmlNode) { } + public ProcDescr() : base() { } + private LazyLoad _MatchProcNumber; + public string MatchProcNumber + { + get + { + return LazyLoad(ref _MatchProcNumber, "@MatchProcNumber"); + } + } + private LazyLoad _ProcDescr1; + public string ProcDescr1 + { + get + { + return LazyLoad(ref _ProcDescr1, "@ProcDescr1"); + } + } + private LazyLoad _ProcDescr2; + public string ProcDescr2 + { + get + { + return LazyLoad(ref _ProcDescr2, "@ProcDescr2"); + } + } + public override string ToString() + { + return string.Format("{0}, {1}", ProcDescr1, MatchProcNumber); + } + } + #region ProcDescrList + [TypeConverter(typeof(vlnListConverter))] + public class ProcDescrList : vlnFormatList + { + public ProcDescrList(XmlNodeList xmlNodeList) : base(xmlNodeList) { } + } + #endregion + #endregion + #endregion + #region ProcDataAll + #region ProcData + [TypeConverter(typeof(ExpandableObjectConverter))] + public class ProcData : vlnFormatItem + { + public ProcData(XmlNode xmlNode): base(xmlNode) {} + private ProcedureSuffixList _ProcedureSuffixList; + public ProcedureSuffixList ProcedureSuffixList + { + get + { + return _ProcedureSuffixList == null? _ProcedureSuffixList = new ProcedureSuffixList(SelectNodes("ProcedureSuffix/string")): _ProcedureSuffixList; + } + set { _ProcedureSuffixList = value; } + } + private ChangeBarData _ChangeBarData; + public ChangeBarData ChangeBarData + { + get + { + return _ChangeBarData == null? _ChangeBarData = new ChangeBarData(SelectSingleNode("ChangeBarData")):_ChangeBarData; + } + } + private CheckOffData _CheckOffData; + public CheckOffData CheckOffData + { + get + { + return _CheckOffData == null? _CheckOffData = new CheckOffData(SelectSingleNode("CheckOffData")):_CheckOffData; + } + } + private LazyLoad _TitleLength; + public int? TitleLength + { + get + { + return LazyLoad(ref _TitleLength, "@TitleLength"); + } + } + private LazyLoad _CoverTitleLength; + public int? CoverTitleLength + { + get + { + return LazyLoad(ref _CoverTitleLength, "@CoverTitleLength"); + } + } + private LazyLoad _ProcedureSuffixFlags; + public string ProcedureSuffixFlags + { + get + { + return LazyLoad(ref _ProcedureSuffixFlags, "@ProcedureSuffixFlags"); + } + } + private LazyLoad _PSInfFile; + public string PSInfFile + { + get + { + return LazyLoad(ref _PSInfFile, "@PSInfFile"); + } + } + private LazyLoad _ForeColor; + public string ForeColor + { + get + { + return LazyLoad(ref _ForeColor, "@ForeColor"); + } + } + private LazyLoad _BackColor; + public string BackColor + { + get + { + return LazyLoad(ref _BackColor, "@BackColor"); + } + } + } + #endregion + #region ProcedureSuffix + [TypeConverter(typeof(ExpandableObjectConverter))] + public class ProcedureSuffix : vlnFormatItem + { + public ProcedureSuffix(XmlNode xmlNode) : base(xmlNode) { } + public ProcedureSuffix() : base() { } + private LazyLoad _Text; + public string Text + { + get + { + return LazyLoad(ref _Text, "text()"); + } + } + public override string GetPDDisplayName() + { return "Text"; } + public override string GetPDDescription() + { return string.Format("ProcedureSuffix '{0}'", Text); } + public override string GetPDCategory() + { return "Procedure Suffix"; } + public override string ToString() + { + return Text; + } + } + #endregion + #region ProcedureSuffixList + [TypeConverter(typeof(vlnListConverter))] + public class ProcedureSuffixList : vlnFormatList + { + public ProcedureSuffixList(XmlNodeList xmlNodeList) : base(xmlNodeList) { } + } + #endregion + #region CheckOffAll + #region CheckOffData + [TypeConverter(typeof(ExpandableObjectConverter))] + public class CheckOffData : vlnFormatItem + { + public CheckOffData(XmlNode xmlNode) : base(xmlNode) { } + private RightCheckOffBoxList _RightCheckOffBoxList; + public RightCheckOffBoxList RightCheckOffBoxList + { + get + { + return _RightCheckOffBoxList == null? _RightCheckOffBoxList = new RightCheckOffBoxList(SelectNodes("RightCheckOffBoxList/RightCheckOffBox")):_RightCheckOffBoxList; + } + } + private CheckOffList _CheckOffList; + public CheckOffList CheckOffList + { + get + { + return _CheckOffList == null? _CheckOffList = new CheckOffList(SelectNodes("CheckOffList/CheckOff")):_CheckOffList; + } + } + private CheckOffHeaderList _CheckOffHeaderList; + public CheckOffHeaderList CheckOffHeaderList + { + get + { + return _CheckOffHeaderList == null? _CheckOffHeaderList = new CheckOffHeaderList(SelectNodes("CheckOffHeaderList/CheckOffHeader")): _CheckOffHeaderList; + } + } + private LazyLoad _UseCheckOffsIn; + public int? UseCheckOffsIn + { + get + { + return LazyLoad(ref _UseCheckOffsIn, "@UseCheckOffsIn"); + } + } + private LazyLoad _CheckOffAdjustment; + public int? CheckOffAdjustment + { + get + { + return LazyLoad(ref _CheckOffAdjustment, "@CheckOffAdjustment"); + } + } + } + #endregion + #region RightCheckOffBox + [TypeConverter(typeof(ExpandableObjectConverter))] + public class RightCheckOffBox : vlnFormatItem + { + public RightCheckOffBox(XmlNode xmlNode) : base(xmlNode) { } + public RightCheckOffBox() : base() { } + private LazyLoad _Index; + public int? Index + { + get + { + return LazyLoad(ref _Index, "@Index"); + } + } + private LazyLoad _RightCheckOffBoxChar; + public int? RightCheckOffBoxChar + { + get + { + return LazyLoad(ref _RightCheckOffBoxChar, "@RightCheckOffBoxChar"); + } + } + public override string GetPDDisplayName() + { return string.Format("[{0}]", Index); } + public override string GetPDDescription() + { return string.Format("[{0}] - {1}", Index, RightCheckOffBoxChar); } + public override string GetPDCategory() + { return "RightCheckOffBox Data"; } + public override string ToString() + { + return RightCheckOffBoxChar.ToString(); + } + } + #endregion + #region RightCheckOffBoxList + [TypeConverter(typeof(vlnListConverter))] + public class RightCheckOffBoxList : vlnFormatList + { + public RightCheckOffBoxList(XmlNodeList xmlNodeList) : base(xmlNodeList) { } + } + #endregion + #region CheckOff + [TypeConverter(typeof(ExpandableObjectConverter))] + public class CheckOff : vlnFormatItem + { + public CheckOff(XmlNode xmlNode) : base(xmlNode) { } + public CheckOff() : base() { } + private LazyLoad _Index; + public int? Index + { + get + { + return LazyLoad(ref _Index, "@Index"); + } + } + private LazyLoad _RightCheckOffChars; + public int? RightCheckOffChars + { + get + { + return LazyLoad(ref _RightCheckOffChars, "@RightCheckOffChars"); + } + } + private LazyLoad _CheckOffWidAdjust; + public int? CheckOffWidAdjust + { + get + { + return LazyLoad(ref _CheckOffWidAdjust, "@CheckOffWidAdjust"); + } + } + private LazyLoad _RightCheckOffPrompt; + public string RightCheckOffPrompt + { + get + { + return LazyLoad(ref _RightCheckOffPrompt, "@RightCheckOffPrompt"); + } + } + public override string GetPDDisplayName() + { return string.Format("[{0}]",Index); } + public override string GetPDDescription() + { return string.Format("[{0}] - {1}", Index, RightCheckOffPrompt); } + public override string GetPDCategory() + { return "Checkoff Data"; } + public override string ToString() + { + return RightCheckOffPrompt; + } + } + #endregion + #region CheckOffList + [TypeConverter(typeof(vlnListConverter))] + public class CheckOffList : vlnFormatList + { + public CheckOffList(XmlNodeList xmlNodeList) : base(xmlNodeList) { } + } + #endregion + #region CheckOffHeader + [TypeConverter(typeof(ExpandableObjectConverter))] + public class CheckOffHeader : vlnFormatItem + { + public CheckOffHeader(XmlNode xmlNode) : base(xmlNode) { } + public CheckOffHeader() : base() { } + private LazyLoad _Index; + public int? Index + { + get + { + return LazyLoad(ref _Index, "@Index"); + } + } + private VE_Font _Font; + public VE_Font Font + { + get + { + return (_Font == null ? _Font = new VE_Font(base.XmlNode) : _Font); + } + } + private LazyLoad _CheckOffHeading; + public string CheckOffHeading + { + get + { + return LazyLoad(ref _CheckOffHeading, "@CheckOffHeading"); + } + } + public override string GetPDDisplayName() + { return string.Format("[{0}]", Index); } + public override string GetPDDescription() + { return string.Format("[{0}] - {1}", Index, CheckOffHeading); } + public override string GetPDCategory() + { return "Checkoff Header Data"; } + public override string ToString() + { + return CheckOffHeading; + } + } + #endregion + #region CheckOffHeaderList + [TypeConverter(typeof(vlnListConverter))] + public class CheckOffHeaderList : vlnFormatList + { + public CheckOffHeaderList(XmlNodeList xmlNodeList) : base(xmlNodeList) { } + } + #endregion + #endregion + #region ChangeBarData + [TypeConverter(typeof(ExpandableObjectConverter))] + public class ChangeBarData : vlnFormatItem + { + public ChangeBarData(XmlNode xmlNode) : base(xmlNode) { } + private LazyLoad _ChangeBarMessage; + public string ChangeBarMessage + { + get + { + return LazyLoad(ref _ChangeBarMessage, "@ChangeBarMessage"); + } + } + private LazyLoad _FixedChangeColumn; + public int? FixedChangeColumn + { + get + { + return LazyLoad(ref _FixedChangeColumn, "@FixedChangeColumn"); + } + } + private LazyLoad _FixedAERChangeColumn; + public int? FixedAERChangeColumn + { + get + { + return LazyLoad(ref _FixedAERChangeColumn, "@FixedAERChangeColumn"); + } + } + private LazyLoad _ChangeSummaryStyle; + public E_Style? ChangeSummaryStyle + { + get + { + return LazyLoad(ref _ChangeSummaryStyle, "@ChangeSummaryStyle"); + } + } + private LazyLoad _ChangeBarStyle; + public E_Style? ChangeBarStyle + { + get + { + return LazyLoad(ref _ChangeBarStyle, "@ChangeBarStyle"); + } + } + private LazyLoad _SpecialChangeBar; + public string SpecialChangeBar + { + get + { + return LazyLoad(ref _SpecialChangeBar, "@SpecialChangeBar"); + } + } + } + #endregion + #endregion + #region SectDataAll + #region SectData + [TypeConverter(typeof(ExpandableObjectConverter))] + public class SectData : vlnFormatItem + { + public SectData(XmlNode xmlNode) : base(xmlNode) { } + private SectionNumber _SectionNumber; + public SectionNumber SectionNumber + { + get + { + if (_SectionNumber == null) _SectionNumber = new SectionNumber(SelectSingleNode("SectionNumber")); + return _SectionNumber; + } + } + private SectionHeader _SectionHeader; + public SectionHeader SectionHeader + { + get + { + if (_SectionHeader == null) _SectionHeader = new SectionHeader(SelectSingleNode("SectionHeader")); + return _SectionHeader; + } + } + private StepSectionData _StepSectionData; + public StepSectionData StepSectionData + { + get + { + if (_StepSectionData == null) _StepSectionData = new StepSectionData(SelectSingleNode("StepSectionData")); + return _StepSectionData; + } + } + private AccSectionData _AccSectionData; + public AccSectionData AccSectionData + { + get + { + if (_AccSectionData == null) _AccSectionData = new AccSectionData(SelectSingleNode("AccSectionData")); + return _AccSectionData; + } + } + private MetaSectionList _MetaSectionList; + public MetaSectionList MetaSectionList + { + get + { + if (_MetaSectionList == null) _MetaSectionList = new MetaSectionList(SelectNodes("MetaSectionData/MetaSection")); + return _MetaSectionList; + } + set { _MetaSectionList = value; } + } + private ReplaceStrList _ReplaceStrList; + public ReplaceStrList ReplaceStrList + { + get + { + return (_ReplaceStrList == null) ? _ReplaceStrList = new ReplaceStrList(SelectNodes("ReplaceStrData/ReplaceStr")) : _ReplaceStrList; + } + set { _ReplaceStrList = value; } + } + private LazyLoad _SectionTitleLength; + public int? SectionTitleLength + { + get + { + return LazyLoad(ref _SectionTitleLength, "@SectionTitleLength"); + } + } + private LazyLoad _ForeColor; + public string ForeColor + { + get + { + return LazyLoad(ref _ForeColor, "@ForeColor"); + } + } + private LazyLoad _BackColor; + public string BackColor + { + get + { + return LazyLoad(ref _BackColor, "@BackColor"); + } + } + } + #endregion + #region SectionNumber + [TypeConverter(typeof(ExpandableObjectConverter))] + public class SectionNumber : vlnFormatItem + { + public SectionNumber(XmlNode xmlNode) : base(xmlNode) { } + public SectionNumber() : base() { } + private LazyLoad _Pos; + public int? Pos + { + get + { + return LazyLoad(ref _Pos, "@Pos"); + } + } + private LazyLoad _Just; + public string Just + { + get + { + return LazyLoad(ref _Just, "@Just"); + } + } + private VE_Font _Font; + public VE_Font Font + { + get + { + return (_Font == null ? _Font = new VE_Font(base.XmlNode) : _Font); + } + } + } + #endregion + #region SectionHeader + [TypeConverter(typeof(ExpandableObjectConverter))] + public class SectionHeader : vlnFormatItem + { + public SectionHeader(XmlNode xmlNode) : base(xmlNode) { } + public SectionHeader() : base() { } + private LazyLoad _Pos; + public int? Pos + { + get + { + return LazyLoad(ref _Pos, "@Pos"); + } + } + private LazyLoad _Just; + public string Just + { + get + { + return LazyLoad(ref _Just, "@Just"); + } + } + private VE_Font _Font; + public VE_Font Font + { + get + { + return (_Font == null ? _Font = new VE_Font(base.XmlNode) : _Font); + } + } + } + #endregion + #region StepSectionDataAll + #region StepSectionData + [TypeConverter(typeof(ExpandableObjectConverter))] + public class StepSectionData : vlnFormatItem + { + public StepSectionData(XmlNode xmlNode) : base(xmlNode) { } + private TextTypeValueList _TextTypeValueList; + public TextTypeValueList TextTypeValueList + { + get + { + return (_TextTypeValueList == null)? _TextTypeValueList = new TextTypeValueList(SelectNodes("TextTypeValue/short")): _TextTypeValueList; + } + set { _TextTypeValueList = value; } + } + private TextTypeList _TextTypeList; + public TextTypeList TextTypeList + { + get + { + return (_TextTypeList == null)? _TextTypeList = new TextTypeList(SelectNodes("TextType/string")): _TextTypeList; + } + set { _TextTypeList = value; } + } + //private SeqTabList _SeqTabList; + //public SeqTabList SeqTabList + //{ + // get + // { + // return (_SeqTabList == null)? _SeqTabList = new SeqTabList(SelectNodes("SeqTab/string")): _SeqTabList; + // } + // set { _SeqTabList = value; } + //} + //private PreSeqTabEditList _PreSeqTabEditList; + //public PreSeqTabEditList PreSeqTabEditList + //{ + // get + // { + // return (_PreSeqTabEditList == null) ?_PreSeqTabEditList = new PreSeqTabEditList(SelectNodes("PreSeqTabEdit/string")): _PreSeqTabEditList; + // } + // set { _PreSeqTabEditList = value; } + //} + //private PreSeqTabPrintList _PreSeqTabPrintList; + //public PreSeqTabPrintList PreSeqTabPrintList + //{ + // get + // { + // return (_PreSeqTabPrintList == null)? _PreSeqTabPrintList = new PreSeqTabPrintList(SelectNodes("PreSeqTabPrint/string")):_PreSeqTabPrintList; + // } + // set { _PreSeqTabPrintList = value; } + //} + //private PostSeqTabEditList _PostSeqTabEditList; + //public PostSeqTabEditList PostSeqTabEditList + //{ + // get + // { + // return (_PostSeqTabEditList == null)? _PostSeqTabEditList = new PostSeqTabEditList(SelectNodes("PostSeqTabEdit/string")): _PostSeqTabEditList; + // } + // set { _PostSeqTabEditList = value; } + //} + //private PostSeqTabPrintList _PostSeqTabPrintList; + //public PostSeqTabPrintList PostSeqTabPrintList + //{ + // get + // { + // return (_PostSeqTabPrintList == null)? _PostSeqTabPrintList = new PostSeqTabPrintList(SelectNodes("PostSeqTabPrint/string")): _PostSeqTabPrintList; + // } + // set { _PostSeqTabPrintList = value; } + //} + private UnderlineTerminateList _UnderlineTerminateList; + public UnderlineTerminateList UnderlineTerminateList + { + get + { + return (_UnderlineTerminateList == null)? _UnderlineTerminateList = new UnderlineTerminateList(SelectNodes("UnderlineTerminate/string")):_UnderlineTerminateList; + } + set { _UnderlineTerminateList = value; } + } + private ObserveNCString1List _ObserveNCString1List; + public ObserveNCString1List ObserveNCString1List + { + get + { + return (_ObserveNCString1List == null)? _ObserveNCString1List = new ObserveNCString1List(SelectNodes("ObserveNCString1/string")): _ObserveNCString1List; + } + set { _ObserveNCString1List = value; } + } + private ObserveNCString2List _ObserveNCString2List; + public ObserveNCString2List ObserveNCString2List + { + get + { + return (_ObserveNCString2List == null)? _ObserveNCString2List = new ObserveNCString2List(SelectNodes("ObserveNCString2/string")):_ObserveNCString2List; + } + set { _ObserveNCString2List = value; } + } + private StepSectionLayoutData _StepSectionLayoutData; + public StepSectionLayoutData StepSectionLayoutData + { + get + { + return (_StepSectionLayoutData == null)? _StepSectionLayoutData = new StepSectionLayoutData(SelectSingleNode("StpSectLayData")):_StepSectionLayoutData; + } + } + private StepSectionEditData _StepSectionEditData; + public StepSectionEditData StepSectionEditData + { + get + { + return (_StepSectionEditData == null)? _StepSectionEditData = new StepSectionEditData(SelectSingleNode("StpSectEditData")): _StepSectionEditData; + } + } + private SeqTabFmtList _SeqTabFmtList; + public SeqTabFmtList SeqTabFmtList + { + get + { + return (_SeqTabFmtList == null) ? _SeqTabFmtList = new SeqTabFmtList(SelectNodes("SequentialTabFormat/SeqTabFmt")) : _SeqTabFmtList; + } + } + private StepSectionPrintData _StepSectionPrintData; + public StepSectionPrintData StepSectionPrintData + { + get + { + return (_StepSectionPrintData == null) ? _StepSectionPrintData = new StepSectionPrintData(SelectSingleNode("StpSectPrtData")) : _StepSectionPrintData; + } + } + private LazyLoad _TopRow; + public int? TopRow + { + get + { + return LazyLoad(ref _TopRow, "@TopRow"); + } + } + //private LazyLoad _SeqStart; + //public string SeqStart + //{ + // get + // { + // return LazyLoad(ref _SeqStart, "@SeqStart"); + // } + //} + //private LazyLoad _LeftJustSeqTab; + //public string LeftJustSeqTab + //{ + // get + // { + // return LazyLoad(ref _LeftJustSeqTab, "@LeftJustSeqTab") ; + // } + //} + //private LazyLoad _HighSeqStart; + //public int? HighSeqStart + //{ + // get + // { + // return LazyLoad(ref _HighSeqStart, "@HighSeqStart"); + // } + //} + private LazyLoad _IndentToken; + public string IndentToken + { + get + { + return LazyLoad(ref _IndentToken, "@IndentToken"); + } + } + private LazyLoad _NumberOfHighLevelSteps; + public int? NumberOfHighLevelSteps + { + get + { + return LazyLoad(ref _NumberOfHighLevelSteps, "@NumberOfHighLevelSteps"); + } + } + private LazyLoad _NumberOfSubStypeTypes; + public int? NumberOfSubStypeTypes + { + get + { + return LazyLoad(ref _NumberOfSubStypeTypes, "@NumberOfSubStepTypes"); + } + } + private LazyLoad _IdentB; + public string IdentB + { + get + { + return LazyLoad(ref _IdentB, "@IdentB"); + } + } + } + #endregion + #region TextTypeValue + [TypeConverter(typeof(ExpandableObjectConverter))] + public class TextTypeValue : vlnFormatItem + { + public TextTypeValue(XmlNode xmlNode) : base(xmlNode) { } + public TextTypeValue() : base() { } + private LazyLoad _TheValue; + public int? TheValue + { + get + { + return LazyLoad(ref _TheValue, "text()"); + } + } + public override string GetPDDisplayName() + { return "Value"; } + public override string GetPDDescription() + { return string.Format("TextTypeValue '{0}'", TheValue); } + public override string GetPDCategory() + { return "Text Type Value"; } + public override string ToString() + { + return TheValue.ToString(); + } + } + #endregion + #region TextTypeValueList + [TypeConverter(typeof(vlnListConverter))] + public class TextTypeValueList : vlnFormatList + { + public TextTypeValueList(XmlNodeList xmlNodeList) : base(xmlNodeList) { } + } + #endregion + #region TextType + [TypeConverter(typeof(ExpandableObjectConverter))] + public class TextType : vlnFormatItem + { + public TextType(XmlNode xmlNode) : base(xmlNode) { } + public TextType() : base() { } + //[Category("Strings")] + private LazyLoad _Text; + public string Text + { + get + { + return LazyLoad(ref _Text, "text()"); + } + } + public override string GetPDDisplayName() + { return "Text"; } + public override string GetPDDescription() + { return string.Format("TextType '{0}'", Text); } + public override string GetPDCategory() + { return "Text Type"; } + public override string ToString() + { + return Text; + } + } + #endregion + #region TextTypeList + [TypeConverter(typeof(vlnListConverter))] + public class TextTypeList : vlnFormatList + { + public TextTypeList(XmlNodeList xmlNodeList) : base(xmlNodeList) { } + } + #endregion + #region OLD - SeqTab + //[TypeConverter(typeof(ExpandableObjectConverter))] + //public class SeqTab : vlnFormatItem + //{ + // public SeqTab(XmlNode xmlNode) : base(xmlNode) { } + // public SeqTab() : base() { } + // private LazyLoad _Text; + // public string Text + // { + // get + // { + // return LazyLoad(ref _Text, "text()"); + // } + // } + // public override string GetPDDisplayName() + // { return "Text"; } + // public override string GetPDDescription() + // { return string.Format("SeqTab '{0}'", Text); } + // public override string GetPDCategory() + // { return "Seq Tab"; } + // public override string ToString() + // { + // return Text; + // } + //} + #endregion + #region OLD - SeqTabList + //[TypeConverter(typeof(vlnListConverter))] + //public class SeqTabList : vlnFormatList + //{ + // public SeqTabList(XmlNodeList xmlNodeList) : base(xmlNodeList) { } + //} + #endregion + #region OLD - PreSeqTabEdit + //[TypeConverter(typeof(ExpandableObjectConverter))] + //public class PreSeqTabEdit : vlnFormatItem + //{ + // public PreSeqTabEdit(XmlNode xmlNode) : base(xmlNode) { } + // public PreSeqTabEdit() : base() { } + // //[Category("Strings")] + // private LazyLoad _Text; + // public string Text + // { + // get + // { + // return LazyLoad(ref _Text, "text()"); + // } + // } + // public override string GetPDDisplayName() + // { return "Text"; } + // public override string GetPDDescription() + // { return string.Format("PreSeqTabEdit '{0}'", Text); } + // public override string GetPDCategory() + // { return "PreSeq Tab Edit"; } + // public override string ToString() + // { + // return Text; + // } + //} + #endregion + #region OLD - PreSeqTabEditList + //[TypeConverter(typeof(vlnListConverter))] + //public class PreSeqTabEditList : vlnFormatList + //{ + // public PreSeqTabEditList(XmlNodeList xmlNodeList) : base(xmlNodeList) { } + //} + #endregion + #region OLD - PreSeqTabPrint + //[TypeConverter(typeof(ExpandableObjectConverter))] + //public class PreSeqTabPrint : vlnFormatItem + //{ + // public PreSeqTabPrint(XmlNode xmlNode) : base(xmlNode) { } + // public PreSeqTabPrint() : base() { } + // private LazyLoad _Text; + // public string Text + // { + // get + // { + // return LazyLoad(ref _Text, "text()"); + // } + // } + // public override string GetPDDisplayName() + // { return "Text"; } + // public override string GetPDDescription() + // { return string.Format("PreSeqTabPrint '{0}'", Text); } + // public override string GetPDCategory() + // { return "PreSeq Tab Printt"; } + // public override string ToString() + // { + // return Text; + // } + //} + #endregion + #region OLD - PreSeqTabPrintList + //[TypeConverter(typeof(vlnListConverter))] + //public class PreSeqTabPrintList : vlnFormatList + //{ + // public PreSeqTabPrintList(XmlNodeList xmlNodeList) : base(xmlNodeList) { } + //} + #endregion + #region OLD - PostSeqTabEdit + //[TypeConverter(typeof(ExpandableObjectConverter))] + //public class PostSeqTabEdit : vlnFormatItem + //{ + // public PostSeqTabEdit(XmlNode xmlNode) : base(xmlNode) { } + // public PostSeqTabEdit() : base() { } + // private LazyLoad _Text; + // public string Text + // { + // get + // { + // return LazyLoad(ref _Text, "text()"); + // } + // } + // public override string GetPDDisplayName() + // { return "Text"; } + // public override string GetPDDescription() + // { return string.Format("PostSeqTabEdit '{0}'", Text); } + // public override string GetPDCategory() + // { return "PostSeq Tab Edit"; } + // public override string ToString() + // { + // return Text; + // } + //} + #endregion + #region OLD - PostSeqTabEditList + //[TypeConverter(typeof(vlnListConverter))] + //public class PostSeqTabEditList : vlnFormatList + //{ + // public PostSeqTabEditList(XmlNodeList xmlNodeList) : base(xmlNodeList) { } + //} + #endregion + #region OLD - PostSeqTabPrint + //[TypeConverter(typeof(ExpandableObjectConverter))] + //public class PostSeqTabPrint : vlnFormatItem + //{ + // public PostSeqTabPrint(XmlNode xmlNode) : base(xmlNode) { } + // public PostSeqTabPrint() : base() { } + // private LazyLoad _Text; + // public string Text + // { + // get + // { + // return LazyLoad(ref _Text, "text()"); + // } + // } + // public override string GetPDDisplayName() + // { return "Text"; } + // public override string GetPDDescription() + // { return string.Format("PostSeqTabPrint '{0}'", Text); } + // public override string GetPDCategory() + // { return "PostSeq Tab Printt"; } + // public override string ToString() + // { + // return Text; + // } + //} + #endregion + #region OLD - PostSeqTabPrintList + //[TypeConverter(typeof(vlnListConverter))] + //public class PostSeqTabPrintList : vlnFormatList + //{ + // public PostSeqTabPrintList(XmlNodeList xmlNodeList) : base(xmlNodeList) { } + //} + #endregion + #region UnderlineTerminate + [TypeConverter(typeof(ExpandableObjectConverter))] + public class UnderlineTerminate : vlnFormatItem + { + public UnderlineTerminate(XmlNode xmlNode) : base(xmlNode) { } + public UnderlineTerminate() : base() { } + private LazyLoad _Text; + public string Text + { + get + { + return LazyLoad(ref _Text, "text()"); + } + } + public override string GetPDDisplayName() + { return "Text"; } + public override string GetPDDescription() + { return string.Format("UnderlineTerminate '{0}'", Text); } + public override string GetPDCategory() + { return "Underline Terminate"; } + public override string ToString() + { + return Text; + } + } + #endregion + #region UnderlineTerminateList + [TypeConverter(typeof(vlnListConverter))] + public class UnderlineTerminateList : vlnFormatList + { + public UnderlineTerminateList(XmlNodeList xmlNodeList) : base(xmlNodeList) { } + } + #endregion + #region ObserveNCString1 + [TypeConverter(typeof(ExpandableObjectConverter))] + public class ObserveNCString1 : vlnFormatItem + { + public ObserveNCString1(XmlNode xmlNode) : base(xmlNode) { } + public ObserveNCString1() : base() { } + private LazyLoad _Text; + public string Text + { + get + { + return LazyLoad(ref _Text, "text()"); + } + } + public override string GetPDDisplayName() + { return "Text"; } + public override string GetPDDescription() + { return string.Format("ObserveNCString1 '{0}'", Text); } + public override string GetPDCategory() + { return "ObserveNCString1"; } + public override string ToString() + { + return Text; + } + } + #endregion + #region ObserveNCString1List + [TypeConverter(typeof(vlnListConverter))] + public class ObserveNCString1List : vlnFormatList + { + public ObserveNCString1List(XmlNodeList xmlNodeList) : base(xmlNodeList) { } + } + #endregion + #region ObserveNCString2 + [TypeConverter(typeof(ExpandableObjectConverter))] + public class ObserveNCString2 : vlnFormatItem + { + public ObserveNCString2(XmlNode xmlNode) : base(xmlNode) { } + public ObserveNCString2() : base() { } + private LazyLoad _Text; + public string Text + { + get + { + return LazyLoad(ref _Text, "text()"); + } + } + public override string GetPDDisplayName() + { return "Text"; } + public override string GetPDDescription() + { return string.Format("ObserveNCString2 '{0}'", Text); } + public override string GetPDCategory() + { return "ObserveNCString2"; } + public override string ToString() + { + return Text; + } + } + #endregion + #region ObserveNCString2List + [TypeConverter(typeof(vlnListConverter))] + public class ObserveNCString2List : vlnFormatList + { + public ObserveNCString2List(XmlNodeList xmlNodeList) : base(xmlNodeList) { } + } + #endregion + #region ReplaceStr + [TypeConverter(typeof(ExpandableObjectConverter))] + public class ReplaceStr : vlnFormatItem + { + public ReplaceStr(XmlNode xmlNode) : base(xmlNode) { } + public ReplaceStr() : base() { } + [Category("Strings")] + private LazyLoad _ReplaceWord; + public string ReplaceWord + { + get + { + return LazyLoad(ref _ReplaceWord, "@ReplaceWord"); + } + } + [Category("Strings")] + private LazyLoad _ReplaceWith; + public string ReplaceWith + { + get + { + return LazyLoad(ref _ReplaceWith, "@ReplaceWith"); + } + } + private LazyLoad _Flag; + public E_ReplaceFlags? Flag + { + get + { + return LazyLoad(ref _Flag, "@Flag"); + } + } + public override string GetPDDisplayName() + { return ReplaceWord; } + public override string GetPDDescription() + { return string.Format("Replace '{0}' with '{1}'",ReplaceWord,ReplaceWith); } + public override string GetPDCategory() + { return "Words to Replace"; } + public override string ToString() + { + return ReplaceWith; + } + } + + #endregion + #region ReplaceStrList + [TypeConverter(typeof(vlnListConverter))] + public class ReplaceStrList : vlnFormatList + { + public ReplaceStrList(XmlNodeList xmlNodeList) : base(xmlNodeList) { } + } + #endregion + #region StepSectionLayoutData + public class StepSectionLayoutData : vlnFormatItem + { + public StepSectionLayoutData(XmlNode xmlNode) : base(xmlNode) { } + private TopOfPage _TopOfPage; + public TopOfPage TopOfPage + { + get + { + return (_TopOfPage == null)? _TopOfPage = new TopOfPage(SelectSingleNode("TopOfPage")): _TopOfPage; + } + } + private Separator _Separator; + public Separator Separator + { + get + { + return (_Separator == null) ?_Separator = new Separator(SelectSingleNode("Separator")):_Separator; + } + } + private LazyLoad _LastLineToStartStep; + public int? LastLineToStartStep + { + get + { + return LazyLoad(ref _LastLineToStartStep, "@LastLineToStartStep"); + } + } + private LazyLoad _LineDrawingOption; + public int? LineDrawingOption + { + get + { + return LazyLoad(ref _LineDrawingOption, "@LineDrawingOption"); + } + } + private LazyLoad _ColS; + public int? ColS + { + get + { + return LazyLoad(ref _ColS, "@ColS"); + } + } + private LazyLoad _ColT; + public int? ColT + { + get + { + return LazyLoad(ref _ColT, "@ColT"); + } + } + private LazyLoad _ColAbs; + public int? ColAbs + { + get + { + return LazyLoad(ref _ColAbs, "@ColAbs"); + } + } + private LazyLoad _WidT; + public int? WidT + { + get + { + return LazyLoad(ref _WidT, "@WidT"); + } + } + private LazyLoad _PMode; + public int? PMode + { + get + { + return LazyLoad(ref _PMode, "@PMode"); + } + } + private LazyLoad _MaxRNO; + public int? MaxRNO + { + get + { + return LazyLoad(ref _MaxRNO, "@MaxRNO"); + } + } + private LazyLoad _MaxRNOTable; + public string MaxRNOTable + { + get + { + return LazyLoad(ref _MaxRNOTable, "@MaxRNOTable"); + } + } + private LazyLoad _ColRTable; + public string ColRTable + { + get + { + return LazyLoad(ref _ColRTable, "@ColRTable"); + } + } + private LazyLoad _WidSTableEdit; + public string WidSTableEdit + { + get + { + return LazyLoad(ref _WidSTableEdit, "@WidSTableEdit"); + } + } + private LazyLoad _WidSTablePrint; + public string WidSTablePrint + { + get + { + return LazyLoad(ref _WidSTablePrint, "@WidSTablePrint"); + } + } + private LazyLoad _AdjRNOCol; + public int? AdjRNOCol + { + get + { + return LazyLoad(ref _AdjRNOCol, "@AdjRNOCol"); + } + } + private LazyLoad _EndMessagePos; + public int? EndMessagePos + { + get + { + return LazyLoad(ref _EndMessagePos, "@EndMessagePos"); + } + } + private LazyLoad _RNOWidthAlt; + public string RNOWidthAlt + { + get + { + return LazyLoad(ref _RNOWidthAlt, "@RNOWidthAlt"); + } + } + private LazyLoad _HLSWidthOVRD; + public int? HLSWidthOVRD + { + get + { + return LazyLoad(ref _HLSWidthOVRD, "@HLSWidthOVRD"); + } + } + private LazyLoad _SubPaginationWght; + public int? SubPaginationWght + { + get + { + return LazyLoad(ref _SubPaginationWght, "@SubPaginationWght"); + } + } + private LazyLoad _TextTitleAdjustment; + public int? TextTitleAdjustment + { + get + { + return LazyLoad(ref _TextTitleAdjustment, "@TextTitleAdjustment"); + } + } + private VE_Font _VertStyle; + public VE_Font VertStyle + { + get + { + return (_VertStyle == null)? _VertStyle = new VE_Font(base.XmlNode): _VertStyle; + } + } + private LazyLoad _TableCenterPos; + public string TableCenterPos + { + get + { + return LazyLoad(ref _TableCenterPos, "@TableCenterPos"); + } + } + private LazyLoad _LowerLimitDivisor; + public string LowerLimitDivisor + { + get + { + return LazyLoad(ref _LowerLimitDivisor, "@LowerLimitDivisor"); + } + } + private LazyLoad _NonLinkedStepNumber; + public string NonLinkedStepNumber + { + get + { + return LazyLoad(ref _NonLinkedStepNumber, "@NonLinkedStepNumber"); + } + } + private LazyLoad _NonLinkedCautNoteNumber; + public string NonLinkedCautNoteNumber + { + get + { + return LazyLoad(ref _NonLinkedCautNoteNumber, "@NonLinkedCautNoteNumber"); + } + } + private LazyLoad _NonLinkedRNONumber; + public string NonLinkedRNONumber + { + get + { + return LazyLoad(ref _NonLinkedRNONumber, "@NonLinkedRNONumber"); + } + } + } + #endregion + #region TopOfPage + public class TopOfPage : vlnFormatItem + { + public TopOfPage(XmlNode xmlNode) : base(xmlNode) { } + private LazyLoad _Row; + public int? Row + { + get + { + return LazyLoad(ref _Row, "@Row"); + } + } + private LazyLoad _Col; + public int? Col + { + get + { + return LazyLoad(ref _Col, "@Col"); + } + } + private VE_Font _Font; + public VE_Font Font + { + get + { + return (_Font == null? _Font = new VE_Font(base.XmlNode): _Font); + } + } + } + #endregion + #region Separator + public class Separator : vlnFormatItem + { + public Separator(XmlNode xmlNode) : base(xmlNode) { } + private LazyLoad _SeparatorLocation; + public int? SeparatorLocation + { + get + { + return LazyLoad(ref _SeparatorLocation, "@SeparatorLocation"); + } + } + private VE_Font _Font; + public VE_Font Font + { + get + { + return (_Font == null ? _Font = new VE_Font(base.XmlNode) : _Font); + } + } + } + #endregion + #region StepSectionEditData + public class StepSectionEditData : vlnFormatItem + { + public StepSectionEditData(XmlNode xmlNode) : base(xmlNode) { } + private LazyLoad _ColSScreenAdj; + public int? ColSScreenAdj + { + get + { + return LazyLoad(ref _ColSScreenAdj, "@ColSScreenAdj"); + } + } + private LazyLoad _ScrnAdjRNOText; + public int? ScrnAdjRNOText + { + get + { + return LazyLoad(ref _ScrnAdjRNOText, "@ScrnAdjRNOText"); + } + } + private LazyLoad _ColRScreen; + public string ColRScreen + { + get + { + return LazyLoad(ref _ColRScreen, "@ColRScreen"); + } + } + } + #endregion + #region StepSectionPrintData + public class StepSectionPrintData : vlnFormatItem + { + public StepSectionPrintData(XmlNode xmlNode) : base(xmlNode) { } + private LazyLoad _ImmStepHdrCol; + public int? ImmStepHdrCol + { + get + { + return LazyLoad(ref _ImmStepHdrCol, "@ImmStepHdrCol"); + } + } + private LazyLoad _SecColHdrforActPMode; + public int? SecColHdrforActPMode + { + get + { + return LazyLoad(ref _SecColHdrforActPMode, "@SecColHdrforActPMode"); + } + } + private LazyLoad _RNOSepString; + public string RNOSepString + { + get + { + return LazyLoad(ref _RNOSepString, "@RNOSepString"); + } + } + private LazyLoad _HLStpSeparatorString; + public string HLStpSeparatorString + { + get + { + return LazyLoad(ref _HLStpSeparatorString, "@HLStpSeparatorString"); + } + } + private LazyLoad _HLRNOStpSeparatorString; + public string HLRNOStpSeparatorString + { + get + { + return LazyLoad(ref _HLRNOStpSeparatorString, "@HLRNOStpSeparatorString"); + } + } + private VE_Font _ModifiedTextStyle; + public VE_Font ModifiedTextStyle + { + get + { + return (_ModifiedTextStyle == null)? _ModifiedTextStyle = new VE_Font(base.XmlNode):_ModifiedTextStyle; + } + } + private VE_Font _ImmStepHdrStyle; + public VE_Font ImmStepHdrStyle + { + get + { + return (_ImmStepHdrStyle == null)? _ImmStepHdrStyle = new VE_Font(base.XmlNode):_ImmStepHdrStyle; + } + } + private ImmStepHdrList _ImmStepHdrList; + public ImmStepHdrList ImmStepHdrList + { + get + { + return (_ImmStepHdrList == null)? _ImmStepHdrList = new ImmStepHdrList(SelectNodes("ImmStepHdrList/string")):_ImmStepHdrList; + } + set { _ImmStepHdrList = value; } + } + } + #region ImmStepHdr + [TypeConverter(typeof(ExpandableObjectConverter))] + public class ImmStepHdr : vlnFormatItem + { + public ImmStepHdr(XmlNode xmlNode) : base(xmlNode) { } + public ImmStepHdr() : base() { } + private LazyLoad _Text; + public string Text + { + get + { + return LazyLoad(ref _Text, "text()"); + } + } + public override string GetPDDisplayName() + { return "Text"; } + public override string GetPDDescription() + { return string.Format("ImmStepHdr '{0}'", Text); } + public override string GetPDCategory() + { return "Imm Step Hdr"; } + public override string ToString() + { + return Text; + } + } + #endregion + #region ImmStepHdrList + [TypeConverter(typeof(vlnListConverter))] + public class ImmStepHdrList : vlnFormatList + { + public ImmStepHdrList(XmlNodeList xmlNodeList) : base(xmlNodeList) { } + } + #endregion + #endregion + #region SeqTabFmtAll + #region SeqTabFmt + [TypeConverter(typeof(ExpandableObjectConverter))] + public class SeqTabFmt : vlnFormatItem + { + public SeqTabFmt() : base() { } + private LazyLoad _Index; //not included - is it needed? + [Description("SeqTab Index")] + public int? Index + { + get + { + return LazyLoad(ref _Index, "@Index"); + } + } + private LazyLoad _LeftJustify; + public int? LeftJustify + { + get + { + return LazyLoad(ref _LeftJustify, "@LeftJustify"); + } + } + private LazyLoad _TabFormat; + public string TabFormat + { + get + { + return LazyLoad(ref _TabFormat, "@TabFormat"); + } + } + public override string GetPDDisplayName() + { return string.Format("Index [{0}]",Index); } + public override string GetPDDescription() + { return string.Format("Sequential Tab Format Index '{0}' Format '{1}'", Index, TabFormat); } + public override string GetPDCategory() + { return "Sequential Tab Formatting"; } + public override string ToString() + { + return TabFormat; + } + } + #endregion + #region SeqTabFmtList + [TypeConverter(typeof(vlnListConverter))] + public class SeqTabFmtList : vlnFormatList + { + public new SeqTabFmt this[int index] + { + get + { + foreach (SeqTabFmt seqTabFmt in this) + if (seqTabFmt.Index == index) return seqTabFmt; + return null; + } + } + public SeqTabFmtList(XmlNodeList xmlNodeList) : base(xmlNodeList) { } + } + #endregion + #endregion + #endregion + #region AccSectionDataAll + #region AccSectionData + [TypeConverter(typeof(ExpandableObjectConverter))] + public class AccSectionData : vlnFormatItem + { + public AccSectionData(XmlNode xmlNode) : base(xmlNode) { } + private LazyLoad _AutoContActSumSection; + public int? AutoContActSumSection + { + get + { + return LazyLoad(ref _AutoContActSumSection, "@AutoContActSumSection"); + } + } + private TableOfContentsData _TableOfContentsData; + public TableOfContentsData TableOfContentsData + { + get + { + return (_TableOfContentsData == null ? _TableOfContentsData = new TableOfContentsData(SelectSingleNode("TableOfContentsData")) : _TableOfContentsData); + } + } + } + #endregion + #region TableOfContentsData + public class TableOfContentsData : vlnFormatItem + { + public TableOfContentsData(XmlNode xmlNode) : base(xmlNode) { } + private LazyLoad _TofCSecNumPos; + public int? TofCSecNumPos + { + get + { + return LazyLoad(ref _TofCSecNumPos, "@TofCSecNumPos"); + } + } + private LazyLoad _TofCSecTitlePos; + public int? TofCSecTitlePos + { + get + { + return LazyLoad(ref _TofCSecTitlePos, "@TofCSecTitlePos"); + } + } + private LazyLoad _TofCSecTitleLen; + public int? TofCSecTitleLen + { + get + { + return LazyLoad(ref _TofCSecTitleLen, "@TofCSecTitleLen"); + } + } + private LazyLoad _TofCPageNumPos; + public int? TofCPageNumPos + { + get + { + return LazyLoad(ref _TofCPageNumPos, "@TofCPageNumPos"); + } + } + private LazyLoad _TofCSpaceChar; + public int? TofCSpaceChar + { + get + { + return LazyLoad(ref _TofCSpaceChar, "@TofCSpaceChar"); + } + } + private LazyLoad _TofCLineSpacing; + public int? TofCLineSpacing + { + get + { + return LazyLoad(ref _TofCLineSpacing, "@TofCLineSpacing"); + } + } + private VE_Font _Font; + public VE_Font Font + { + get + { + return (_Font == null) ?_Font = new VE_Font(base.XmlNode):_Font; + } + } + } + #endregion + #endregion + #region MetaSectionAll + #region MetaSection + [TypeConverter(typeof(ExpandableObjectConverter))] + public class MetaSection : vlnFormatItem + { + public MetaSection(XmlNode xmlNode) : base(xmlNode) { } + public MetaSection() : base() { } + private LazyLoad _Index; + public int? Index + { + get + { + return LazyLoad(ref _Index, "@Index"); + } + } + private LazyLoad _SecNumPositionAdj; + public int? SecNumPositionAdj + { + get + { + return LazyLoad(ref _SecNumPositionAdj, "@SecNumPositionAdj"); + } + } + private LazyLoad _SecTitlePositionAdj; + public int? SecTitlePositionAdj + { + get + { + return LazyLoad(ref _SecTitlePositionAdj, "@SecTitlePositionAdj"); + } + } + private LazyLoad _ColSByLevel; + public int? ColSByLevel + { + get + { + return LazyLoad(ref _ColSByLevel, "@ColSByLevel"); + } + } + private LazyLoad _TofCPositionAdj; + public int? TofCPositionAdj + { + get + { + return LazyLoad(ref _TofCPositionAdj, "@TofCPositionAdj"); + } + } + private LazyLoad _WidSAdjByLevel; + public int? WidSAdjByLevel + { + get + { + return LazyLoad(ref _WidSAdjByLevel, "@WidSAdjByLevel"); + } + } + public override string GetPDDisplayName() + { return string.Format("[{0}]", Index); } + public override string GetPDCategory() + { return "Meta Section Values"; } + public override string ToString() + { + return String.Format("{0}, {1}, {2}, {3}, {4}", SecNumPositionAdj, SecTitlePositionAdj, ColSByLevel, TofCPositionAdj, TofCPositionAdj); + } + } + + #endregion + #region MetaSectionList + [TypeConverter(typeof(vlnListConverter))] + public class MetaSectionList : vlnFormatList + { + public MetaSectionList(XmlNodeList xmlNodeList) : base(xmlNodeList) { } + } + #endregion + #endregion + #endregion + #region StepDataAll + #region Step + [TypeConverter(typeof(ExpandableObjectConverter))] + public class StepData : vlnFormatItem + { + public StepData() : base() { } + private LazyLoad _Index; + [Description("Step Index")] + public int? Index + { + get + { + return LazyLoad(ref _Index, "@Index"); + } + } + private LazyLoad _Type; + public string Type + { + get + { + return LazyLoad(ref _Type, "@Type"); + } + } + private LazyLoad _ParentType; + public string ParentType + { + get + { + return LazyLoad(ref _ParentType, "@ParentType"); + } + } + private LazyLoad _StepTypeColOverride; + public string StepTypeColOverride + { + get + { + + return LazyLoad(ref _StepTypeColOverride, "@StepTypeColOverride"); + } + } + private LazyLoad _Sep; + public string Sep + { + get + { + return LazyLoad(ref _Sep, "@Sep"); + } + } + private LazyLoad _AlternateName; + public string AlternateName + { + get + { + return LazyLoad(ref _AlternateName, "@AlternateName"); + } + } + private LazyLoad _Prefix; + public string Prefix + { + get + { + return LazyLoad(ref _Prefix, "@Prefix"); + } + } + private LazyLoad _Suffix; + public string Suffix + { + get + { + return LazyLoad(ref _Suffix, "@Suffix"); + } + } + private LazyLoad _UnderlineTheseChar; + public string UnderlineTheseChar + { + get + { + return LazyLoad(ref _UnderlineTheseChar, "@UnderlineTheseChar"); + } + } + private LazyLoad _VertPos; + public string VertPos + { + get + { + return LazyLoad(ref _VertPos, "@VertPos"); + } + } + private VE_Font _Font; + public VE_Font Font + { + get + { + return (_Font == null) ?_Font = new VE_Font(base.XmlNode): _Font; + } + } + private StepLayoutData _StepLayoutData; + public StepLayoutData StepLayoutData + { + get + { + return (_StepLayoutData == null)? _StepLayoutData = new StepLayoutData(base.XmlNode): _StepLayoutData; + } + } + private StepEditData _StepEditData; + public StepEditData StepEditData + { + get + { + return (_StepEditData == null) ? _StepEditData = new StepEditData(base.XmlNode) : _StepEditData; + } + } + private TabData _TabData; + public TabData TabData + { + get + { + return (_TabData == null) ? _TabData = new TabData(base.XmlNode) : _TabData; + } + } + public override string ToString() + { + return string.Format("{0}", Type); + } + } + #endregion + #region StepDataList + [TypeConverter(typeof(vlnListConverter))] + public class StepDataList : vlnFormatList + { + public new StepData this[int index] + { + get + { + foreach (StepData stepData in this) + if (stepData.Index == index) return stepData; + return null; + } + } + public StepDataList(XmlNodeList xmlNodeList) : base(xmlNodeList) { } + } + #endregion + #region StepLayoutData + [TypeConverter(typeof(ExpandableObjectConverter))] + public class StepLayoutData : vlnFormatItem + { + public StepLayoutData(XmlNode xmlNode) + : base(xmlNode) + { + } + private LazyLoad _ForeColor; + public string ForeColor + { + get + { + return LazyLoad(ref _ForeColor, "StepLayoutData/@ForeColor"); + } + } + private LazyLoad _BackColor; + public string BackColor + { + get + { + return LazyLoad(ref _BackColor, "StepLayoutData/@BackColor"); + } + } + private LazyLoad _STExtralines; + public int? STExtralines + { + get + { + return LazyLoad(ref _STExtralines, "StepLayoutData/@STExtralines"); + } + } + private LazyLoad _STBoxindex; + public int? STBoxindex + { + get + { + return LazyLoad(ref _STBoxindex, "StepLayoutData/@STBoxindex"); + } + } + private LazyLoad _EveryNLines; + public int? EveryNLines + { + get + { + return LazyLoad(ref _EveryNLines, "StepLayoutData/@EveryNLines"); + } + } + } + #endregion + #region StepEditData + [TypeConverter(typeof(ExpandableObjectConverter))] + public class StepEditData : vlnFormatItem + { + public StepEditData(XmlNode xmlNode) + : base(xmlNode) + { + } + private LazyLoad _ForeColor; + public string ForeColor + { + get + { + return LazyLoad(ref _ForeColor, "StepEditData/@ForeColor"); + } + } + private LazyLoad _BackColor; + public string BackColor + { + get + { + return LazyLoad(ref _BackColor, "StepEditData/@BackColor"); + } + } + private LazyLoad _AcTable; + public E_AccStep? AcTable + { + get + { + return LazyLoad(ref _AcTable, "StepEditData/@AcTable"); + } + } + } + #endregion + #region StepTab + [TypeConverter(typeof(ExpandableObjectConverter))] + public class TabData : vlnFormatItem + { + public TabData(XmlNode xmlNode) + : base(xmlNode) + { + } + private LazyLoad _IdentEdit; + public string IdentEdit + { + get + { + return LazyLoad(ref _IdentEdit, "TabData/@IdentEdit"); + } + } + private LazyLoad _IdentPrint; + public string IdentPrint + { + get + { + return LazyLoad(ref _IdentPrint, "TabData/@IdentPrint"); + } + } + private LazyLoad _AltPrintTBIdent; + public string AltPrintTBIdent + { + get + { + return LazyLoad(ref _AltPrintTBIdent, "TabData/@AltPrintTBIdent"); + } + } + private LazyLoad _RNOIdentEdit; + public string RNOIdentEdit + { + get + { + return LazyLoad(ref _RNOIdentEdit, "TabData/@RNOIdentEdit"); + } + } + private LazyLoad _RNOIdentPrint; + public string RNOIdentPrint + { + get + { + return LazyLoad(ref _RNOIdentPrint, "TabData/@RNOIdentPrint"); + } + } + private VE_Font _Font; + public VE_Font Font + { + get + { + return (_Font == null ? _Font = new VE_Font(base.XmlNode) : _Font); + } + } + } + #endregion + #endregion + #region BoxDataAll + #region Box + [TypeConverter(typeof(ExpandableObjectConverter))] + public class Box : vlnFormatItem + { + public Box(XmlNode xmlNode) : base(xmlNode) { } + public Box() : base() { } + private LazyLoad _Index; + public int? Index + { + get + { + return LazyLoad(ref _Index, "@Index"); + } + } + private LazyLoad _Start; + public int? Start + { + get + { + return LazyLoad(ref _Start, "@Start"); + } + } + private LazyLoad _End; + public int? End + { + get + { + return LazyLoad(ref _End, "@End"); + } + } + private LazyLoad _TxtStart; + public int? TxtStart + { + get + { + return LazyLoad(ref _TxtStart, "@TxtStart"); + } + } + private LazyLoad _TxtWidth; + public int? TxtWidth + { + get + { + return LazyLoad(ref _TxtWidth, "@TxtWidth"); + } + } + private LazyLoad _Height; + public int? Height + { + get + { + return LazyLoad(ref _Height, "@Height"); + } + } + private LazyLoad _TabPos; + public int? TabPos + { + get + { + return LazyLoad(ref _TabPos, "@TabPos"); + } + } + private LazyLoad _TxtRowAdj; + public int? TxtRowAdj + { + get + { + return LazyLoad(ref _TxtRowAdj, "@TxtRowAdj"); + } + } + private LazyLoad _BXURC; + public string BXURC + { + get + { + return LazyLoad(ref _BXURC, "@BXURC"); + } + } + private LazyLoad _BXHorz; + public string BXHorz + { + get + { + return LazyLoad(ref _BXHorz, "@BXHorz"); + } + } + private LazyLoad _BXULC; + public string BXULC + { + get + { + return LazyLoad(ref _BXULC, "@BXULC"); + } + } + private LazyLoad _BXVert; + public string BXVert + { + get + { + return LazyLoad(ref _BXVert, "@BXVert"); + } + } + private LazyLoad _BXMLS; + public string BXMLS + { + get + { + return LazyLoad(ref _BXMLS, "@BXMLS"); + } + } + private LazyLoad _BXMRS; + public string BXMRS + { + get + { + return LazyLoad(ref _BXMRS, "@BXMRS"); + } + } + private LazyLoad _BXLRC; + public string BXLRC + { + get + { + return LazyLoad(ref _BXLRC, "@BXLRC"); + } + } + private LazyLoad _BXLLC; + public string BXLLC + { + get + { + return LazyLoad(ref _BXLLC, "@BXLLC"); + } + } + private LazyLoad _BXMID; + public string BXMID + { + get + { + return LazyLoad(ref _BXMID, "@BXMID"); + } + } + private LazyLoad _BXLHorz; + public string BXLHorz + { + get + { + return LazyLoad(ref _BXLHorz, "@BXLHorz"); + } + } + private LazyLoad _BXUMID; + public string BXUMID + { + get + { + return LazyLoad(ref _BXUMID, "@BXUMID"); + } + } + private LazyLoad _BXLMID; + public string BXLMID + { + get + { + return LazyLoad(ref _BXLMID, "@BXLMID"); + } + } + private VE_Font _Font; + public VE_Font Font + { + get + { + return (_Font == null) ?_Font = new VE_Font(base.XmlNode):_Font; + } + } + public override string GetPDDisplayName() + { return string.Format("[{0}]", Index); } + public override string GetPDCategory() + { return "Box Definition"; } + public override string ToString() + { + return String.Format("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}", + BXURC, BXHorz, BXULC, BXVert, BXMLS, BXMRS, BXLRC, BXLLC, BXMID, BXLHorz, BXUMID, BXLMID); + } + } + #endregion + #region BoxList + [TypeConverter(typeof(vlnListConverter))] + public class BoxList : vlnFormatList + { + public BoxList(XmlNodeList xmlNodeList) : base(xmlNodeList) { } + } + #endregion + #endregion + #region TransDataAll + #region TransData + [TypeConverter(typeof(ExpandableObjectConverter))] + public class TransData : vlnFormatItem + { + private TransTypeList _TransTypeList; + public TransTypeList TransTypeList + { + get + { + return(_TransTypeList == null)? _TransTypeList = new TransTypeList(SelectNodes("TransTypeData/TransTypes")): _TransTypeList; + } + } + public TransData(XmlNode xmlNode) : base(xmlNode) { } + private LazyLoad _DelimiterForTransitionTitle; + public string DelimiterForTransitionTitle + { + get + { + return LazyLoad(ref _DelimiterForTransitionTitle, "@DelimiterForTransitionTitle"); + } + } + private LazyLoad _StepSubstepDelimeter; + public string StepSubstepDelimeter + { + get + { + return LazyLoad(ref _StepSubstepDelimeter, "@StepSubstepDelimeter"); + } + } + private LazyLoad _ThroughString; + public string ThroughString + { + get + { + return LazyLoad(ref _ThroughString, "@ThroughString"); + } + } + } + #endregion + #region TransType + [TypeConverter(typeof(ExpandableObjectConverter))] + public class TransType : vlnFormatItem + { + public TransType(XmlNode xmlNode) : base(xmlNode) { } + public TransType() : base() { } + private LazyLoad _Index; + public int? Index + { + get + { + return LazyLoad(ref _Index, "@Index"); + } + } + private LazyLoad _Type; + public int? Type + { + get + { + return LazyLoad(ref _Type, "@TransType"); + } + } + private LazyLoad _TransFormat; + public string TransFormat + { + get + { + return LazyLoad(ref _TransFormat, "@TransFormat"); + } + } + private LazyLoad _TransMenu; + public string TransMenu + { + get + { + return LazyLoad(ref _TransMenu, "@TransMenu"); + } + } + public override string GetPDDisplayName() + { return string.Format("[{0}] - Type {1}", Index, Type); } + public override string GetPDCategory() + { return "Transition Type Data"; } + public override string ToString() + { + return string.Format("{0} - {1}",TransFormat, TransMenu); + } + } + #endregion + #region TransTypeList + [TypeConverter(typeof(vlnListConverter))] + public class TransTypeList : vlnFormatList + { + public TransTypeList(XmlNodeList xmlNodeList) : base(xmlNodeList) { } + } + #endregion + #endregion +} + diff --git a/PROMS/VEPROMS.CSLA.Library/Format/vlnFormat.cs b/PROMS/VEPROMS.CSLA.Library/Format/vlnFormat.cs new file mode 100644 index 00000000..ba59cf52 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Format/vlnFormat.cs @@ -0,0 +1,428 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.ComponentModel; + +namespace VEPROMS.CSLA.Library +{ + #region vlnFormatDocument + public class vlnFormatDocument:XmlDocument + { + private static XmlElement mydocele; + public vlnFormatDocument(Format myFormat) + { + _MyFormat = myFormat; + LoadXml(MyFormat.Data); + mydocele = this.DocumentElement; + } + private Format _MyFormat; + public Format MyFormat + { + get { return _MyFormat; } + set { _MyFormat = value; } + } + public static XmlNode LookupSingleNode(XmlNode xmlNode, string path) + { + //original: + //if (xmlNode == null) return null; + //XmlNode xn = xmlNode.SelectSingleNode(path); + //if (xn != null) return xn; + //if (xmlNode.Name == "Step") xn = LookupSingleStepNode(xmlNode, path); + //if (xn != null) return xn; + //if (path.StartsWith("Font")) return LookupSingleFontNode(xmlNode, path); + //return InheritLookup(xmlNode, path); + + if (path.StartsWith("Font")) + { + XmlNode xn = null; + if (xmlNode != null) + { + xn = xmlNode.SelectSingleNode(path); + if (xn != null) return xn; + } + else + { + xmlNode = LookupSingleNode(mydocele.FirstChild, "/PlantFormat/FormatData"); + } + return LookupSingleFontNode(xmlNode, path); + } + else + { + if (xmlNode == null) return null; + XmlNode xn = xmlNode.SelectSingleNode(path); + if (xn != null) return xn; + if (xmlNode.Name == "Step") xn = LookupSingleStepNode(xmlNode, path); + if (xn != null) return xn; + if (path.StartsWith("Font")) return LookupSingleFontNode(xmlNode, path); + return InheritLookup(xmlNode, path, false); + } + } + public static XmlNode LookupSingleFontNode(XmlNode xmlNode, string path) + { + if (xmlNode == null) return null; + XmlNode tmpNode = xmlNode; + XmlNode xn = xmlNode.SelectSingleNode(path); + while (xn == null)//Walk-up the format tree to find a font node + { + if (xmlNode.NodeType == XmlNodeType.Document) + { + return LookupSingleNode(tmpNode, "/PlantFormat/FormatData/" + path); + } + xmlNode = xmlNode.ParentNode; + xn = xmlNode.SelectSingleNode(path); + } + return xn; + } + public static XmlNode LookupSingleStepNode(XmlNode xmlNode, string path) + { + if (xmlNode == null) return null; + XmlNode xn = xmlNode.SelectSingleNode(path); + XmlNode tmpNode = xmlNode; + XmlNode tmpNode2 = xmlNode; + while (xn == null) //Walk-up the format tree to find a step node + { + tmpNode = xmlNode; + xmlNode = xmlNode.ParentNode.SelectSingleNode(string.Format("Step[@Type='{0}']",xmlNode.Attributes["ParentType"].InnerText)); + if (xmlNode == null && path.StartsWith("Font")) return LookupSingleFontNode(tmpNode, path); + if (xmlNode == null) + return InheritLookup(tmpNode2, path, true); + xn = xmlNode.SelectSingleNode(path); + } + return xn; + } + public static XmlNodeList LookupNodes(XmlNode xmlNode, string path) + { + if (xmlNode == null) return null; + XmlNodeList xl = xmlNode.SelectNodes(path); + if (xl == null) xl = InheritLookupNodes(xmlNode, path); + if (xl == null) return null; + return xl; + } + public static string Lookup(XmlNode xmlNode, string path) + { + //if (xmlNode == null) return null; + XmlNode xn = LookupSingleNode(xmlNode, path); + //if (xn == null) xn = InheritLookup(xmlNode, path); + if (xn == null) return null; + return xn.InnerText; + } + //public static string StepLookup(XmlNode xmlNode, string path) + //{ + // //if (xmlNode == null) return null; + // XmlNode xn = LookupSingleStepNode(xmlNode, path); + // //if (xn == null) xn = InheritLookup(xmlNode, path); + // if (xn == null) return null; + // return xn.InnerText; + //} + public static T EnumLookup(XmlNode xmlNode, string path) + { + string str = Lookup(xmlNode,path); + if (str == null) return default(T); + return (T)Enum.Parse(typeof(T), str); + } + public static int? IntLookup(XmlNode xmlNode, string path) + { + //if (xmlNode == null) return null; + //XmlNode xn = LookupSingleNode(xmlNode, path); + //if (xn == null) xn = InheritLookup(xmlNode, path); + //if (xn == null) return null; + //return int.Parse(xn.InnerText); + string str = Lookup(xmlNode, path); + if (str == null) return null; + return int.Parse(str); + } + public static int SiblingCount(XmlNode xmlNode) + { + int retval = 0; + string nodeName = xmlNode.Name; + for (XmlNode xn = xmlNode; xn != null; xn = xn.PreviousSibling) + { + if (xn.Name == nodeName) retval++; + } + return retval; + } + public static string Path(XmlNode xmlNode) + { + // Walk the path + string parentPath = (xmlNode.ParentNode == xmlNode.OwnerDocument ? "" : Path(xmlNode.ParentNode)); + // Count Siblings with the Same Name + int sibCount = SiblingCount(xmlNode); + return string.Format("{0}/{1}[{2}]", parentPath, xmlNode.Name, sibCount); + } + public static XmlNode InheritLookup(XmlNode xmlNode, string path, bool stepLookup) + { + stepLookup = false; // 8/2 change for inheritance + if (xmlNode == null) return null;// No path to match + string xPath = Path(xmlNode);// Build xPath from xmlNode + vlnFormatDocument fd = (vlnFormatDocument)(xmlNode.OwnerDocument);//First Get the vlnFormatDocument + while(fd.MyFormat.MyParent != null) + { + fd = fd.MyFormat.MyParent.PlantFormat.XmlDoc;// Get the parents vlnFormatDocument + if (fd != null) + { + XmlNode xp; + if (path.StartsWith("/")) xp = fd.DocumentElement; + else xp = fd.SelectSingleNode(xPath);// Get the related node + if (xp != null) + { + XmlNode xn = null; + if (stepLookup) + xn = LookupSingleStepNode(xp, path); + else + xn = xp.SelectSingleNode(path); + if(xn != null) return xn; + } + } + } + return null; + } + public static XmlNodeList InheritLookupNodes(XmlNode xmlNode, string path) + { + if (xmlNode == null) return null;// No path to match + string xPath = Path(xmlNode);// Build xPath from xmlNode + vlnFormatDocument fd = (vlnFormatDocument)(xmlNode.OwnerDocument);//First Get the vlnFormatDocument + while (fd.MyFormat.MyParent != null) + { + fd = fd.MyFormat.MyParent.PlantFormat.XmlDoc;// Get the parents vlnFormatDocument + if (fd != null) + { + XmlNode xp = fd.SelectSingleNode(xPath);// Get the related node + if (xp != null) + { + XmlNodeList xl = xp.SelectNodes(path); + if (xl != null) return xl; + } + } + } + return null; + } + } + #endregion + #region vlnFormatItem + [TypeConverter(typeof(ExpandableObjectConverter))] + public class vlnFormatItem + { + public vlnFormatItem(XmlNode xmlNode) + { + _XmlNode = xmlNode; + } + public vlnFormatItem() { } + XmlNode _XmlNode; + internal XmlNode XmlNode + { + get { return _XmlNode; } + set { _XmlNode = value; } + } + public virtual string GetPDDisplayName() + { return ToString(); } + public virtual string GetPDName() + { return ToString(); } + public virtual string GetPDDescription() + { return ToString(); } + public virtual string GetPDCategory() + { return ToString(); } + public XmlNodeList SelectNodes(string path) + { + return vlnFormatDocument.LookupNodes(_XmlNode, path); + } + public XmlNode SelectSingleNode(string path) + { + return vlnFormatDocument.LookupSingleNode(_XmlNode, path); + } + public XmlNode SelectSingleFontNode(string path) + { + return vlnFormatDocument.LookupSingleFontNode(_XmlNode, path); + } + public string Lookup(string path) + { + return vlnFormatDocument.Lookup(_XmlNode, path); + } + public string Lookup(string path, ref string local) + { + return (local != null? local : local = Lookup(path)); + } + //public string StepLookup(string path) + //{ + // return vlnFormatDocument.StepLookup(_XmlNode, path); + //} + public int? IntLookup(string path) + { + return vlnFormatDocument.IntLookup(_XmlNode, path); + } + public int? IntLookup(string path, ref int? local) + { + return (local != null ? local : local = IntLookup(path)); + } + public T EnumLookup(string path) + { + return vlnFormatDocument.EnumLookup(_XmlNode, path); + } + public string LazyLoad(ref LazyLoad ll, string xPath) + { + if (ll == null) + { + XmlNode xn = SelectSingleNode(xPath); + ll = new LazyLoad(xn != null ? xn.InnerText : null); + } + return ll.Value; + } + public int? LazyLoad(ref LazyLoad ll, string xPath) + { + if (ll == null) + { + XmlNode xn = SelectSingleNode(xPath); + ll = new LazyLoad(xn != null ? (int?)int.Parse(xn.InnerText) : null); + } + return ll.Value; + } + public Nullable LazyLoad(ref LazyLoad> ll, string xPath) + where T:struct + { + if (ll == null) + { + XmlNode xn = SelectSingleNode(xPath); + ll = new LazyLoad>(xn != null ? (Nullable)Enum.Parse(typeof(T), xn.InnerText) : null); + } + return ll.Value; + } + } + #endregion + #region LazyLoad + public class LazyLoad + { + public LazyLoad(T value) + { + _Value = value; + } + private T _Value; + public T Value + { + get { return _Value; } + set { _Value = value; } + } + } + #endregion + #region vlnFormatList, new() + public class vlnFormatList : List, ICustomTypeDescriptor + where T : vlnFormatItem, new() + { + private XmlNodeList _XmlNodeList; + internal XmlNodeList XmlNodeList + { + get { return _XmlNodeList; } + set { _XmlNodeList = value; } + } + public vlnFormatList(XmlNodeList xmlNodeList) + { + _XmlNodeList = xmlNodeList; + foreach (XmlNode xn in _XmlNodeList) + { + T tt = new T(); + tt.XmlNode = xn; + Add(tt); + } + } + #region ICustomTypeDescriptor + 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; } + public PropertyDescriptorCollection GetProperties(Attribute[] attributes) + { return GetProperties(); } + public virtual PropertyDescriptorCollection GetProperties() + { + // Create a collection object to hold property descriptors + PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null); + // Iterate the list + int i = 0; + for (i = 0; i < this.Count; i++) + { + // Create a property descriptor for the item and add to the property descriptor collection + pds.Add(new vlnPropertyDescriptor, T>(this, i)); + } + // return the property descriptor collection + return pds; + } + #endregion + } + #endregion + #region vlnListConverter + internal class vlnListConverter : ExpandableObjectConverter + where T : vlnFormatList + where C : vlnFormatItem, new() + { + private string Plural(string name) + { + if (name.EndsWith("y")) return name.Substring(0, name.Length - 1) + "ies"; + if (name.EndsWith("ss")) return name + "es"; + else return name + "s"; + } + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is T) + { + // Return department and department role separated by comma. + return ((T)value).Count.ToString() + " " + (((T)value).Count == 1 ? typeof(C).Name : Plural(typeof(C).Name)); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion + #region vlnPropertyDescriptor + public class vlnPropertyDescriptor : PropertyDescriptor + where T : vlnFormatList + where C : vlnFormatItem, new() + { + protected C _Item = null; + public vlnPropertyDescriptor(T itemList, int index) + : base("#" + index.ToString(), null) + { + _Item = itemList[index]; + } + public override bool CanResetValue(object component) + { return true; } + public override Type ComponentType + { get { return _Item.GetType(); } } + public override object GetValue(object component) + { return _Item; } + public override bool IsReadOnly + { get { return true; } } + public override Type PropertyType + { get { return _Item.GetType(); } } + public override void ResetValue(object component) + { ;} + public override bool ShouldSerializeValue(object component) + { return true; } + public override void SetValue(object component, object value) + { /*_Item = value*/;} + //public override AttributeCollection Attributes + //{ get { return new AttributeCollection(null); } } + public override string DisplayName + { get { return _Item.GetPDDisplayName(); } } + public override string Description + { get { return _Item.GetPDDescription(); } } + public override string Name + { get { return _Item.GetPDName(); } } + public override string Category + { get { return _Item.GetPDCategory(); } } + } // Class + #endregion +} + diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Annotation.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Annotation.cs new file mode 100644 index 00000000..39eb6630 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Annotation.cs @@ -0,0 +1,1098 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +using Csla.Validation; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Annotation tmp in _AllList) + { + _AllByPrimaryKey[tmp.AnnotationID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (Annotation tmp in remove) + _AllList.Remove(tmp); + } + public static Annotation GetExistingByPrimaryKey(int annotationID) + { + ConvertListToDictionary(); + string key = annotationID.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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; } } + protected Annotation() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(AnnotationID.ToString()); + } + 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) + 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 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) + 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 Annotation Get(int annotationID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Annotation"); + try + { + Annotation tmp = GetExistingByPrimaryKey(annotationID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(annotationID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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(); + _AllList.Add(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 + + +//// The following is a sample Extension File. You can use it to create AnnotationExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class Annotation +// { +// partial class AnnotationExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUserID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationInfo.cs new file mode 100644 index 00000000..3bc29491 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationInfo.cs @@ -0,0 +1,407 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (AnnotationInfo tmp in _AllList) + { + _AllByPrimaryKey[tmp.AnnotationID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (AnnotationInfo tmp in remove) + _AllList.Remove(tmp); + } + internal static void AddList(AnnotationInfoList lst) + { + foreach (AnnotationInfo item in lst) _AllList.Add(item); + } + public static AnnotationInfo GetExistingByPrimaryKey(int annotationID) + { + ConvertListToDictionary(); + string key = annotationID.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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 AnnotationInfo() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(AnnotationID.ToString()); + } + public virtual Annotation Get() + { + return _Editable = Annotation.Get(_AnnotationID); + } + public static void Refresh(Annotation tmp) + { + AnnotationInfo tmpInfo = GetExistingByPrimaryKey(tmp.AnnotationID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(Annotation tmp) + { + _ItemID = tmp.ItemID; + _TypeID = tmp.TypeID; + _RtfText = tmp.RtfText; + _SearchText = tmp.SearchText; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _AnnotationInfoExtension.Refresh(this); + _MyItem = null; + _MyAnnotationType = null; + OnChange();// raise an event + } + public static void Refresh(AnnotationTypeAnnotation tmp) + { + AnnotationInfo tmpInfo = GetExistingByPrimaryKey(tmp.AnnotationID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(AnnotationTypeAnnotation tmp) + { + _ItemID = tmp.ItemID; + _RtfText = tmp.RtfText; + _SearchText = tmp.SearchText; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _AnnotationInfoExtension.Refresh(this); + _MyItem = null; + _MyAnnotationType = null; + OnChange();// raise an event + } + public static void Refresh(ItemAnnotation tmp) + { + AnnotationInfo tmpInfo = GetExistingByPrimaryKey(tmp.AnnotationID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(ItemAnnotation tmp) + { + _TypeID = tmp.TypeID; + _RtfText = tmp.RtfText; + _SearchText = tmp.SearchText; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _AnnotationInfoExtension.Refresh(this); + _MyItem = null; + _MyAnnotationType = null; + 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 = GetExistingByPrimaryKey(annotationID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(annotationID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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/Generated/AnnotationInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationInfoList.cs new file mode 100644 index 00000000..cb5df860 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationInfoList.cs @@ -0,0 +1,312 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +namespace VEPROMS.CSLA.Library +{ + /// + /// AnnotationInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(AnnotationInfoListConverter))] + public partial class AnnotationInfoList : 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 (AnnotationInfo tmp in this) + { + tmp.Changed += new AnnotationInfoEvent(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)); + } + } + public void Dispose() + { + foreach (AnnotationInfo tmp in this) + { + tmp.Changed -= new AnnotationInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static AnnotationInfoList _AnnotationInfoList = null; + /// + /// Return a list of all projects. + /// + public static AnnotationInfoList Get() + { + try + { + if (_AnnotationInfoList != null) + return _AnnotationInfoList; + AnnotationInfoList tmp = DataPortal.Fetch(); + AnnotationInfo.AddList(tmp); + tmp.AddEvents(); + _AnnotationInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on AnnotationInfoList.Get", ex); + } + } + // TODO: Add alternative gets - + //public static AnnotationInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on AnnotationInfoList.Get", ex); + // } + //} + public static AnnotationInfoList GetByTypeID(int typeID) + { + try + { + AnnotationInfoList tmp = DataPortal.Fetch(new TypeIDCriteria(typeID)); + AnnotationInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on AnnotationInfoList.GetByTypeID", ex); + } + } + public static AnnotationInfoList GetByItemID(int itemID) + { + try + { + AnnotationInfoList tmp = DataPortal.Fetch(new ItemIDCriteria(itemID)); + AnnotationInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on AnnotationInfoList.GetByItemID", ex); + } + } + private AnnotationInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] AnnotationInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAnnotations"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new AnnotationInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("AnnotationInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("AnnotationInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class TypeIDCriteria + { + public TypeIDCriteria(int typeID) + { + _TypeID = typeID; + } + private int _TypeID; + public int TypeID + { + get { return _TypeID; } + set { _TypeID = value; } + } + } + private void DataPortal_Fetch(TypeIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] AnnotationInfoList.DataPortal_FetchTypeID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAnnotationsByTypeID"; + cm.Parameters.AddWithValue("@TypeID", criteria.TypeID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new AnnotationInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("AnnotationInfoList.DataPortal_FetchTypeID", ex); + throw new DbCslaException("AnnotationInfoList.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}] AnnotationInfoList.DataPortal_FetchItemID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAnnotationsByItemID"; + cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new AnnotationInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("AnnotationInfoList.DataPortal_FetchItemID", ex); + throw new DbCslaException("AnnotationInfoList.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 + AnnotationInfoListPropertyDescriptor pd = new AnnotationInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class AnnotationInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private AnnotationInfo Item { get { return (AnnotationInfo) _Item;} } + public AnnotationInfoListPropertyDescriptor(AnnotationInfoList collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class AnnotationInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is AnnotationInfoList) + { + // Return department and department role separated by comma. + return ((AnnotationInfoList) value).Items.Count.ToString() + " Annotations"; + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationType.cs b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationType.cs new file mode 100644 index 00000000..0057ed56 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationType.cs @@ -0,0 +1,1097 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +using Csla.Validation; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static Dictionary _AllByName = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (AnnotationType tmp in _AllList) + { + _AllByPrimaryKey[tmp.TypeID.ToString()]=tmp; // Primary Key + _AllByName[tmp.Name.ToString()] = tmp; // Unique Index + remove.Add(tmp); + } + foreach (AnnotationType tmp in remove) + _AllList.Remove(tmp); + } + public static AnnotationType GetExistingByPrimaryKey(int typeID) + { + ConvertListToDictionary(); + string key = typeID.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + return null; + } + public static AnnotationType GetExistingByName(string name) + { + ConvertListToDictionary(); + string key = name.ToString(); + if (_AllByName.ContainsKey(key)) return _AllByName[key]; + 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; } } + protected AnnotationType() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(TypeID.ToString()); + _AllByName.Remove(Name.ToString()); + } + 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) + 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 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) + 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 AnnotationType Get(int typeID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a AnnotationType"); + try + { + AnnotationType tmp = GetExistingByPrimaryKey(typeID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(typeID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") tmp = null; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on AnnotationType.Get", ex); + } + } + private static AnnotationType GetByName(string name) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a AnnotationType"); + try + { + AnnotationType tmp = GetExistingByName(name); + if (tmp == null) + { + tmp=DataPortal.Fetch(new NameCriteria(name)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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(); + _AllList.Add(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 + + +//// The following is a sample Extension File. You can use it to create AnnotationTypeExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class AnnotationType +// { +// partial class AnnotationTypeExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUserID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationTypeAnnotation.cs b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationTypeAnnotation.cs new file mode 100644 index 00000000..605e853a --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationTypeAnnotation.cs @@ -0,0 +1,569 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +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 +} // Namespace + + +//// The following is a sample Extension File. You can use it to create AnnotationTypeAnnotationExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class AnnotationTypeAnnotation +// { +// partial class AnnotationTypeAnnotationExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUserID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationTypeAnnotations.cs b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationTypeAnnotations.cs new file mode 100644 index 00000000..e6b7c49a --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationTypeAnnotations.cs @@ -0,0 +1,290 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using Csla.Validation; +namespace VEPROMS.CSLA.Library +{ + /// + /// AnnotationTypeAnnotations Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(AnnotationTypeAnnotationsConverter))] + public partial class AnnotationTypeAnnotations : BusinessListBase, ICustomTypeDescriptor, 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; } + } + // One To Many + public AnnotationTypeAnnotation this[Annotation myAnnotation] + { + get + { + foreach (AnnotationTypeAnnotation annotation in this) + if (annotation.AnnotationID == myAnnotation.AnnotationID) + return annotation; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public AnnotationTypeAnnotation GetItem(Annotation myAnnotation) + { + foreach (AnnotationTypeAnnotation annotation in this) + if (annotation.AnnotationID == myAnnotation.AnnotationID) + return annotation; + return null; + } + public AnnotationTypeAnnotation Add(Item myItem) // One to Many + { + AnnotationTypeAnnotation annotation = AnnotationTypeAnnotation.New(myItem); + this.Add(annotation); + return annotation; + } + public void Remove(Annotation myAnnotation) + { + foreach (AnnotationTypeAnnotation annotation in this) + { + if (annotation.AnnotationID == myAnnotation.AnnotationID) + { + Remove(annotation); + break; + } + } + } + public bool Contains(Annotation myAnnotation) + { + foreach (AnnotationTypeAnnotation annotation in this) + if (annotation.AnnotationID == myAnnotation.AnnotationID) + return true; + return false; + } + public bool ContainsDeleted(Annotation myAnnotation) + { + foreach (AnnotationTypeAnnotation annotation in DeletedList) + if (annotation.AnnotationID == myAnnotation.AnnotationID) + return true; + return false; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules=null; + foreach(AnnotationTypeAnnotation annotationTypeAnnotation in this) + if ((hasBrokenRules = annotationTypeAnnotation.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static AnnotationTypeAnnotations New() + { + return new AnnotationTypeAnnotations(); + } + internal static AnnotationTypeAnnotations Get(SafeDataReader dr) + { + return new AnnotationTypeAnnotations(dr); + } + public static AnnotationTypeAnnotations GetByTypeID(int typeID) + { + try + { + return DataPortal.Fetch(new TypeIDCriteria(typeID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on AnnotationTypeAnnotations.GetByTypeID", ex); + } + } + private AnnotationTypeAnnotations() + { + MarkAsChild(); + } + internal AnnotationTypeAnnotations(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(AnnotationTypeAnnotation.Get(dr)); + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class TypeIDCriteria + { + public TypeIDCriteria(int typeID) + { + _TypeID = typeID; + } + private int _TypeID; + public int TypeID + { + get { return _TypeID; } + set { _TypeID = value; } + } + } + private void DataPortal_Fetch(TypeIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] AnnotationTypeAnnotations.DataPortal_FetchTypeID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAnnotationsByTypeID"; + cm.Parameters.AddWithValue("@TypeID", criteria.TypeID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new AnnotationTypeAnnotation(dr)); + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("AnnotationTypeAnnotations.DataPortal_FetchTypeID", ex); + throw new DbCslaException("AnnotationTypeAnnotations.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(AnnotationType annotationType) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (AnnotationTypeAnnotation obj in DeletedList) + obj.DeleteSelf(annotationType);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (AnnotationTypeAnnotation obj in this) + { + if (obj.IsNew) + obj.Insert(annotationType); + else + obj.Update(annotationType); + } + } + finally + { + 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 + AnnotationTypeAnnotationsPropertyDescriptor pd = new AnnotationTypeAnnotationsPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class AnnotationTypeAnnotationsPropertyDescriptor : vlnListPropertyDescriptor + { + private AnnotationTypeAnnotation Item { get { return (AnnotationTypeAnnotation) _Item;} } + public AnnotationTypeAnnotationsPropertyDescriptor(AnnotationTypeAnnotations collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class AnnotationTypeAnnotationsConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is AnnotationTypeAnnotations) + { + // Return department and department role separated by comma. + return ((AnnotationTypeAnnotations) value).Items.Count.ToString() + " Annotations"; + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationTypeInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationTypeInfo.cs new file mode 100644 index 00000000..dbadf9a9 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationTypeInfo.cs @@ -0,0 +1,334 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (AnnotationTypeInfo tmp in _AllList) + { + _AllByPrimaryKey[tmp.TypeID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (AnnotationTypeInfo tmp in remove) + _AllList.Remove(tmp); + } + internal static void AddList(AnnotationTypeInfoList lst) + { + foreach (AnnotationTypeInfo item in lst) _AllList.Add(item); + } + public static AnnotationTypeInfo GetExistingByPrimaryKey(int typeID) + { + ConvertListToDictionary(); + string key = typeID.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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 && _AnnotationTypeAnnotations == null) + _AnnotationTypeAnnotations = AnnotationInfoList.GetByTypeID(_TypeID); + return _AnnotationTypeAnnotations; + } + } + // 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 AnnotationTypeInfo() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(TypeID.ToString()); + } + public virtual AnnotationType Get() + { + return _Editable = AnnotationType.Get(_TypeID); + } + public static void Refresh(AnnotationType tmp) + { + AnnotationTypeInfo tmpInfo = GetExistingByPrimaryKey(tmp.TypeID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private 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 = GetExistingByPrimaryKey(typeID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(typeID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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/Generated/AnnotationTypeInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationTypeInfoList.cs new file mode 100644 index 00000000..13064575 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationTypeInfoList.cs @@ -0,0 +1,198 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +namespace VEPROMS.CSLA.Library +{ + /// + /// AnnotationTypeInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(AnnotationTypeInfoListConverter))] + public partial class AnnotationTypeInfoList : 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 (AnnotationTypeInfo tmp in this) + { + tmp.Changed += new AnnotationTypeInfoEvent(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)); + } + } + public void Dispose() + { + foreach (AnnotationTypeInfo tmp in this) + { + tmp.Changed -= new AnnotationTypeInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static AnnotationTypeInfoList _AnnotationTypeInfoList = null; + /// + /// Return a list of all projects. + /// + public static AnnotationTypeInfoList Get() + { + try + { + if (_AnnotationTypeInfoList != null) + return _AnnotationTypeInfoList; + AnnotationTypeInfoList tmp = DataPortal.Fetch(); + AnnotationTypeInfo.AddList(tmp); + tmp.AddEvents(); + _AnnotationTypeInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on AnnotationTypeInfoList.Get", ex); + } + } + // TODO: Add alternative gets - + //public static AnnotationTypeInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on AnnotationTypeInfoList.Get", ex); + // } + //} + private AnnotationTypeInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] AnnotationTypeInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAnnotationTypes"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new AnnotationTypeInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("AnnotationTypeInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("AnnotationTypeInfoList.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 + AnnotationTypeInfoListPropertyDescriptor pd = new AnnotationTypeInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class AnnotationTypeInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private AnnotationTypeInfo Item { get { return (AnnotationTypeInfo) _Item;} } + public AnnotationTypeInfoListPropertyDescriptor(AnnotationTypeInfoList collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class AnnotationTypeInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is AnnotationTypeInfoList) + { + // Return department and department role separated by comma. + return ((AnnotationTypeInfoList) value).Items.Count.ToString() + " AnnotationTypes"; + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Assignment.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Assignment.cs new file mode 100644 index 00000000..532a4d17 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Assignment.cs @@ -0,0 +1,1171 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +using Csla.Validation; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Assignment tmp in _AllList) + { + _AllByPrimaryKey[tmp.AID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (Assignment tmp in remove) + _AllList.Remove(tmp); + } + public static Assignment GetExistingByPrimaryKey(int aid) + { + ConvertListToDictionary(); + string key = aid.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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; } } + protected Assignment() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(AID.ToString()); + } + 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) + 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 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) + 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 Assignment Get(int aid) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Assignment"); + try + { + Assignment tmp = GetExistingByPrimaryKey(aid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(aid)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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(); + _AllList.Add(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 + + +//// The following 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 VEPROMS.CSLA.Library +//{ +// public partial class Assignment +// { +// partial class AssignmentExtension : 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 AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/AssignmentInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/AssignmentInfo.cs new file mode 100644 index 00000000..c9710b79 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/AssignmentInfo.cs @@ -0,0 +1,442 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (AssignmentInfo tmp in _AllList) + { + _AllByPrimaryKey[tmp.AID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (AssignmentInfo tmp in remove) + _AllList.Remove(tmp); + } + internal static void AddList(AssignmentInfoList lst) + { + foreach (AssignmentInfo item in lst) _AllList.Add(item); + } + public static AssignmentInfo GetExistingByPrimaryKey(int aid) + { + ConvertListToDictionary(); + string key = aid.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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 AssignmentInfo() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(AID.ToString()); + } + public virtual Assignment Get() + { + return _Editable = Assignment.Get(_AID); + } + public static void Refresh(Assignment tmp) + { + AssignmentInfo tmpInfo = GetExistingByPrimaryKey(tmp.AID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(Assignment tmp) + { + _GID = tmp.GID; + _RID = tmp.RID; + _FolderID = tmp.FolderID; + _StartDate = tmp.StartDate; + _EndDate = tmp.EndDate; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _AssignmentInfoExtension.Refresh(this); + _MyGroup = null; + _MyRole = null; + _MyFolder = null; + OnChange();// raise an event + } + public static void Refresh(FolderAssignment tmp) + { + AssignmentInfo tmpInfo = GetExistingByPrimaryKey(tmp.AID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(FolderAssignment tmp) + { + _GID = tmp.GID; + _RID = tmp.RID; + _StartDate = tmp.StartDate; + _EndDate = tmp.EndDate; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _AssignmentInfoExtension.Refresh(this); + _MyGroup = null; + _MyRole = null; + _MyFolder = null; + OnChange();// raise an event + } + public static void Refresh(GroupAssignment tmp) + { + AssignmentInfo tmpInfo = GetExistingByPrimaryKey(tmp.AID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(GroupAssignment tmp) + { + _RID = tmp.RID; + _FolderID = tmp.FolderID; + _StartDate = tmp.StartDate; + _EndDate = tmp.EndDate; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _AssignmentInfoExtension.Refresh(this); + _MyGroup = null; + _MyRole = null; + _MyFolder = null; + OnChange();// raise an event + } + public static void Refresh(RoleAssignment tmp) + { + AssignmentInfo tmpInfo = GetExistingByPrimaryKey(tmp.AID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(RoleAssignment tmp) + { + _GID = tmp.GID; + _FolderID = tmp.FolderID; + _StartDate = tmp.StartDate; + _EndDate = tmp.EndDate; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _AssignmentInfoExtension.Refresh(this); + _MyGroup = null; + _MyRole = null; + _MyFolder = null; + 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 = GetExistingByPrimaryKey(aid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(aid)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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/Generated/AssignmentInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/AssignmentInfoList.cs new file mode 100644 index 00000000..60f2eb8c --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/AssignmentInfoList.cs @@ -0,0 +1,369 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +namespace VEPROMS.CSLA.Library +{ + /// + /// AssignmentInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(AssignmentInfoListConverter))] + public partial class AssignmentInfoList : 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 (AssignmentInfo tmp in this) + { + tmp.Changed += new AssignmentInfoEvent(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)); + } + } + public void Dispose() + { + foreach (AssignmentInfo tmp in this) + { + tmp.Changed -= new AssignmentInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static AssignmentInfoList _AssignmentInfoList = null; + /// + /// Return a list of all projects. + /// + public static AssignmentInfoList Get() + { + try + { + if (_AssignmentInfoList != null) + return _AssignmentInfoList; + AssignmentInfoList tmp = DataPortal.Fetch(); + AssignmentInfo.AddList(tmp); + tmp.AddEvents(); + _AssignmentInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on AssignmentInfoList.Get", ex); + } + } + // TODO: Add alternative gets - + //public static AssignmentInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on AssignmentInfoList.Get", ex); + // } + //} + public static AssignmentInfoList GetByFolderID(int folderID) + { + try + { + AssignmentInfoList tmp = DataPortal.Fetch(new FolderIDCriteria(folderID)); + AssignmentInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on AssignmentInfoList.GetByFolderID", ex); + } + } + public static AssignmentInfoList GetByGID(int gid) + { + try + { + AssignmentInfoList tmp = DataPortal.Fetch(new GIDCriteria(gid)); + AssignmentInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on AssignmentInfoList.GetByGID", ex); + } + } + public static AssignmentInfoList GetByRID(int rid) + { + try + { + AssignmentInfoList tmp = DataPortal.Fetch(new RIDCriteria(rid)); + AssignmentInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on AssignmentInfoList.GetByRID", ex); + } + } + private AssignmentInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] AssignmentInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAssignments"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new AssignmentInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("AssignmentInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("AssignmentInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class FolderIDCriteria + { + public FolderIDCriteria(int folderID) + { + _FolderID = folderID; + } + private int _FolderID; + public int FolderID + { + get { return _FolderID; } + set { _FolderID = value; } + } + } + private void DataPortal_Fetch(FolderIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] AssignmentInfoList.DataPortal_FetchFolderID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAssignmentsByFolderID"; + cm.Parameters.AddWithValue("@FolderID", criteria.FolderID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new AssignmentInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("AssignmentInfoList.DataPortal_FetchFolderID", ex); + throw new DbCslaException("AssignmentInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class GIDCriteria + { + public GIDCriteria(int gid) + { + _GID = gid; + } + private int _GID; + public int GID + { + get { return _GID; } + set { _GID = value; } + } + } + private void DataPortal_Fetch(GIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] AssignmentInfoList.DataPortal_FetchGID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAssignmentsByGID"; + cm.Parameters.AddWithValue("@GID", criteria.GID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new AssignmentInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("AssignmentInfoList.DataPortal_FetchGID", ex); + throw new DbCslaException("AssignmentInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class RIDCriteria + { + public RIDCriteria(int rid) + { + _RID = rid; + } + private int _RID; + public int RID + { + get { return _RID; } + set { _RID = value; } + } + } + private void DataPortal_Fetch(RIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] AssignmentInfoList.DataPortal_FetchRID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAssignmentsByRID"; + cm.Parameters.AddWithValue("@RID", criteria.RID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new AssignmentInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("AssignmentInfoList.DataPortal_FetchRID", ex); + throw new DbCslaException("AssignmentInfoList.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 + AssignmentInfoListPropertyDescriptor pd = new AssignmentInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class AssignmentInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private AssignmentInfo Item { get { return (AssignmentInfo) _Item;} } + public AssignmentInfoListPropertyDescriptor(AssignmentInfoList collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class AssignmentInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is AssignmentInfoList) + { + // Return department and department role separated by comma. + return ((AssignmentInfoList) value).Items.Count.ToString() + " Assignments"; + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ChildFolders.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ChildFolders.cs new file mode 100644 index 00000000..93d3825e --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ChildFolders.cs @@ -0,0 +1,309 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using Csla.Validation; +namespace VEPROMS.CSLA.Library +{ + /// + /// ChildFolders Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ChildFoldersConverter))] + public partial class ChildFolders : BusinessListBase, ICustomTypeDescriptor, 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; } + } + // One To Many + public new Folder this[int folderID] + { + get + { + foreach (Folder folder in this) + if (folder.FolderID == folderID) + return folder; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public Folder GetItem(int folderID) + { + foreach (Folder folder in this) + if (folder.FolderID == folderID) + return folder; + return null; + } + public Folder Add(Folder myParent, string name, string shortName) // One to Many with unique fields + { + if (!Contains(name)) + { + Folder folder = Folder.New(myParent, name, shortName); + this.Add(folder); + return folder; + } + else + throw new InvalidOperationException("folder already exists"); + } + public void Remove(int folderID) + { + foreach (Folder folder in this) + { + if (folder.FolderID == folderID) + { + Remove(folder); + break; + } + } + } + public bool Contains(int folderID) + { + foreach (Folder folder in this) + if (folder.FolderID == folderID) + return true; + return false; + } + public bool ContainsDeleted(int folderID) + { + foreach (Folder folder in DeletedList) + if (folder.FolderID == folderID) + return true; + return false; + } + public bool Contains(string name) + { + foreach (Folder folder in this) + if (folder.Name == name) + return true; + return false; + } + public bool ContainsDeleted(string name) + { + foreach (Folder folder in DeletedList) + if (folder.Name == name) + return true; + return false; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules=null; + foreach(Folder folder in this) + if ((hasBrokenRules = folder.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static ChildFolders New() + { + return new ChildFolders(); + } + internal static ChildFolders Get(SafeDataReader dr, Folder parent) + { + return new ChildFolders(dr, parent); + } + public static ChildFolders GetByParentID(int parentID) + { + try + { + return DataPortal.Fetch(new ParentIDCriteria(parentID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ChildFolders.GetByParentID", ex); + } + } + private ChildFolders() + { + MarkAsChild(); + } + internal ChildFolders(SafeDataReader dr, Folder parent) + { + MarkAsChild(); + Fetch(dr, parent); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr, Folder parent) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(Folder.Get(dr, parent)); + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class ParentIDCriteria + { + public ParentIDCriteria(int parentID) + { + _ParentID = parentID; + } + private int _ParentID; + public int ParentID + { + get { return _ParentID; } + set { _ParentID = value; } + } + } + private void DataPortal_Fetch(ParentIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ChildFolders.DataPortal_FetchParentID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getChildFolders"; + cm.Parameters.AddWithValue("@ParentID", criteria.ParentID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new Folder(dr, criteria.ParentID)); + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("ChildFolders.DataPortal_FetchParentID", ex); + throw new DbCslaException("ChildFolders.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(Folder folder) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (Folder obj in DeletedList) + obj.DeleteSelf(folder);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (Folder obj in this) + { + if (obj.IsNew) + obj.SQLInsert(); + else + obj.SQLUpdate(); + } + } + finally + { + 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 + ChildFoldersPropertyDescriptor pd = new ChildFoldersPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class ChildFoldersPropertyDescriptor : vlnListPropertyDescriptor + { + private Folder Item { get { return (Folder) _Item;} } + public ChildFoldersPropertyDescriptor(ChildFolders collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class ChildFoldersConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ChildFolders) + { + // Return department and department role separated by comma. + return ((ChildFolders) value).Items.Count.ToString() + " Folders"; + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ChildFormats.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ChildFormats.cs new file mode 100644 index 00000000..2d3a2eac --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ChildFormats.cs @@ -0,0 +1,309 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using Csla.Validation; +namespace VEPROMS.CSLA.Library +{ + /// + /// ChildFormats Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ChildFormatsConverter))] + public partial class ChildFormats : BusinessListBase, ICustomTypeDescriptor, 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; } + } + // One To Many + public new Format this[int formatID] + { + get + { + foreach (Format format in this) + if (format.FormatID == formatID) + return format; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public Format GetItem(int formatID) + { + foreach (Format format in this) + if (format.FormatID == formatID) + return format; + return null; + } + public Format Add(Format myParent, string name, string data) // One to Many with unique fields + { + if (!Contains(name)) + { + Format format = Format.New(myParent, name, data); + this.Add(format); + return format; + } + else + throw new InvalidOperationException("format already exists"); + } + public void Remove(int formatID) + { + foreach (Format format in this) + { + if (format.FormatID == formatID) + { + Remove(format); + break; + } + } + } + public bool Contains(int formatID) + { + foreach (Format format in this) + if (format.FormatID == formatID) + return true; + return false; + } + public bool ContainsDeleted(int formatID) + { + foreach (Format format in DeletedList) + if (format.FormatID == formatID) + return true; + return false; + } + public bool Contains(string name) + { + foreach (Format format in this) + if (format.Name == name) + return true; + return false; + } + public bool ContainsDeleted(string name) + { + foreach (Format format in DeletedList) + if (format.Name == name) + return true; + return false; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules=null; + foreach(Format format in this) + if ((hasBrokenRules = format.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static ChildFormats New() + { + return new ChildFormats(); + } + internal static ChildFormats Get(SafeDataReader dr, Format parent) + { + return new ChildFormats(dr, parent); + } + public static ChildFormats GetByParentID(int parentID) + { + try + { + return DataPortal.Fetch(new ParentIDCriteria(parentID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ChildFormats.GetByParentID", ex); + } + } + private ChildFormats() + { + MarkAsChild(); + } + internal ChildFormats(SafeDataReader dr, Format parent) + { + MarkAsChild(); + Fetch(dr, parent); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr, Format parent) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(Format.Get(dr, parent)); + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class ParentIDCriteria + { + public ParentIDCriteria(int parentID) + { + _ParentID = parentID; + } + private int _ParentID; + public int ParentID + { + get { return _ParentID; } + set { _ParentID = value; } + } + } + private void DataPortal_Fetch(ParentIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ChildFormats.DataPortal_FetchParentID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getChildFormats"; + cm.Parameters.AddWithValue("@ParentID", criteria.ParentID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new Format(dr, criteria.ParentID)); + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("ChildFormats.DataPortal_FetchParentID", ex); + throw new DbCslaException("ChildFormats.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(Format format) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (Format obj in DeletedList) + obj.DeleteSelf(format);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (Format obj in this) + { + if (obj.IsNew) + obj.SQLInsert(); + else + obj.SQLUpdate(); + } + } + finally + { + 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 + ChildFormatsPropertyDescriptor pd = new ChildFormatsPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class ChildFormatsPropertyDescriptor : vlnListPropertyDescriptor + { + private Format Item { get { return (Format) _Item;} } + public ChildFormatsPropertyDescriptor(ChildFormats collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class ChildFormatsConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ChildFormats) + { + // Return department and department role separated by comma. + return ((ChildFormats) value).Items.Count.ToString() + " Formats"; + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/CommonRules.cs b/PROMS/VEPROMS.CSLA.Library/Generated/CommonRules.cs new file mode 100644 index 00000000..b59fd468 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/CommonRules.cs @@ -0,0 +1,40 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using Csla.Validation; +using System.Reflection; +namespace VEPROMS.CSLA.Library +{ + /// + /// CommonRules Generated by MyGeneration using the CSLA Object Mapping template + /// + public static class CommonRules + { + public static bool Required(object target, Csla.Validation.RuleArgs e) + { + PropertyInfo propertyInfoObj = target.GetType().GetProperty(e.PropertyName); + if (propertyInfoObj == null) return true; + if (propertyInfoObj.GetValue(target, null) == null) + { + e.Description = e.PropertyName + " is a required field"; + return false; + } + return true; + } + } +} \ No newline at end of file diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Connection.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Connection.cs new file mode 100644 index 00000000..780de51b --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Connection.cs @@ -0,0 +1,1195 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +using Csla.Validation; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static Dictionary _AllByName = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Connection tmp in _AllList) + { + _AllByPrimaryKey[tmp.DBID.ToString()]=tmp; // Primary Key + _AllByName[tmp.Name.ToString()] = tmp; // Unique Index + remove.Add(tmp); + } + foreach (Connection tmp in remove) + _AllList.Remove(tmp); + } + public static Connection GetExistingByPrimaryKey(int dbid) + { + ConvertListToDictionary(); + string key = dbid.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + return null; + } + public static Connection GetExistingByName(string name) + { + ConvertListToDictionary(); + string key = name.ToString(); + if (_AllByName.ContainsKey(key)) return _AllByName[key]; + 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; } } + protected Connection() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(DBID.ToString()); + _AllByName.Remove(Name.ToString()); + } + 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 = GetExistingByPrimaryKey(dbid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(dbid)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") tmp = null; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Connection.Get", ex); + } + } + private static Connection GetByName(string name) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Connection"); + try + { + Connection tmp = GetExistingByName(name); + if (tmp == null) + { + tmp=DataPortal.Fetch(new NameCriteria(name)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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(); + _AllList.Add(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 + + +//// The following 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 VEPROMS.CSLA.Library +//{ +// public partial class Connection +// { +// partial class ConnectionExtension : 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 AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ConnectionFolder.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ConnectionFolder.cs new file mode 100644 index 00000000..621188a2 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ConnectionFolder.cs @@ -0,0 +1,613 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +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 != value) + { + _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 _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(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"); + _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, _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, _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 + + +//// The following 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 VEPROMS.CSLA.Library +//{ +// public partial class ConnectionFolder +// { +// partial class ConnectionFolderExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual int DefaultParentID +// { +// get { return 1; } +// } +// public virtual int DefaultDBID +// { +// get { return 1; } +// } +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUsrID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ConnectionFolders.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ConnectionFolders.cs new file mode 100644 index 00000000..49111446 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ConnectionFolders.cs @@ -0,0 +1,290 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using Csla.Validation; +namespace VEPROMS.CSLA.Library +{ + /// + /// ConnectionFolders Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ConnectionFoldersConverter))] + public partial class ConnectionFolders : BusinessListBase, ICustomTypeDescriptor, 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; } + } + // One To Many + public ConnectionFolder this[Folder myFolder] + { + get + { + foreach (ConnectionFolder folder in this) + if (folder.FolderID == myFolder.FolderID) + return folder; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public ConnectionFolder GetItem(Folder myFolder) + { + foreach (ConnectionFolder folder in this) + if (folder.FolderID == myFolder.FolderID) + return folder; + return null; + } + public ConnectionFolder Add(Folder myParent, string name, string shortName) // One to Many + { + ConnectionFolder folder = ConnectionFolder.New(myParent, name, shortName); + this.Add(folder); + return folder; + } + public void Remove(Folder myFolder) + { + foreach (ConnectionFolder folder in this) + { + if (folder.FolderID == myFolder.FolderID) + { + Remove(folder); + break; + } + } + } + public bool Contains(Folder myFolder) + { + foreach (ConnectionFolder folder in this) + if (folder.FolderID == myFolder.FolderID) + return true; + return false; + } + public bool ContainsDeleted(Folder myFolder) + { + foreach (ConnectionFolder folder in DeletedList) + if (folder.FolderID == myFolder.FolderID) + return true; + return false; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules=null; + foreach(ConnectionFolder connectionFolder in this) + if ((hasBrokenRules = connectionFolder.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static ConnectionFolders New() + { + return new ConnectionFolders(); + } + internal static ConnectionFolders Get(SafeDataReader dr) + { + return new ConnectionFolders(dr); + } + public static ConnectionFolders GetByDBID(int dbid) + { + try + { + return DataPortal.Fetch(new DBIDCriteria(dbid)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ConnectionFolders.GetByDBID", ex); + } + } + private ConnectionFolders() + { + MarkAsChild(); + } + internal ConnectionFolders(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(ConnectionFolder.Get(dr)); + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class DBIDCriteria + { + public DBIDCriteria(int dbid) + { + _DBID = dbid; + } + private int _DBID; + public int DBID + { + get { return _DBID; } + set { _DBID = value; } + } + } + private void DataPortal_Fetch(DBIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ConnectionFolders.DataPortal_FetchDBID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getFoldersByDBID"; + cm.Parameters.AddWithValue("@DBID", criteria.DBID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new ConnectionFolder(dr)); + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("ConnectionFolders.DataPortal_FetchDBID", ex); + throw new DbCslaException("ConnectionFolders.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(Connection connection) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (ConnectionFolder obj in DeletedList) + obj.DeleteSelf(connection);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (ConnectionFolder obj in this) + { + if (obj.IsNew) + obj.Insert(connection); + else + obj.Update(connection); + } + } + finally + { + 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 + ConnectionFoldersPropertyDescriptor pd = new ConnectionFoldersPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class ConnectionFoldersPropertyDescriptor : vlnListPropertyDescriptor + { + private ConnectionFolder Item { get { return (ConnectionFolder) _Item;} } + public ConnectionFoldersPropertyDescriptor(ConnectionFolders collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class ConnectionFoldersConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ConnectionFolders) + { + // Return department and department role separated by comma. + return ((ConnectionFolders) value).Items.Count.ToString() + " Folders"; + } + 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 new file mode 100644 index 00000000..00d141c5 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ConnectionInfo.cs @@ -0,0 +1,373 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (ConnectionInfo tmp in _AllList) + { + _AllByPrimaryKey[tmp.DBID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (ConnectionInfo tmp in remove) + _AllList.Remove(tmp); + } + internal static void AddList(ConnectionInfoList lst) + { + foreach (ConnectionInfo item in lst) _AllList.Add(item); + } + public static ConnectionInfo GetExistingByPrimaryKey(int dbid) + { + ConvertListToDictionary(); + string key = dbid.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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 && _ConnectionFolders == null) + _ConnectionFolders = FolderInfoList.GetByDBID(_DBID); + return _ConnectionFolders; + } + } + // 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 */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(DBID.ToString()); + } + public virtual Connection Get() + { + return _Editable = Connection.Get(_DBID); + } + public static void Refresh(Connection tmp) + { + ConnectionInfo tmpInfo = GetExistingByPrimaryKey(tmp.DBID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private 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 = GetExistingByPrimaryKey(dbid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(dbid)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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/Generated/ConnectionInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ConnectionInfoList.cs new file mode 100644 index 00000000..f3048ff3 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ConnectionInfoList.cs @@ -0,0 +1,198 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +namespace VEPROMS.CSLA.Library +{ + /// + /// ConnectionInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ConnectionInfoListConverter))] + public partial class ConnectionInfoList : 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 (ConnectionInfo tmp in this) + { + tmp.Changed += new ConnectionInfoEvent(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)); + } + } + public void Dispose() + { + foreach (ConnectionInfo tmp in this) + { + tmp.Changed -= new ConnectionInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static ConnectionInfoList _ConnectionInfoList = null; + /// + /// Return a list of all projects. + /// + public static ConnectionInfoList Get() + { + try + { + if (_ConnectionInfoList != null) + return _ConnectionInfoList; + ConnectionInfoList tmp = DataPortal.Fetch(); + ConnectionInfo.AddList(tmp); + tmp.AddEvents(); + _ConnectionInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ConnectionInfoList.Get", ex); + } + } + // TODO: Add alternative gets - + //public static ConnectionInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on ConnectionInfoList.Get", ex); + // } + //} + private ConnectionInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ConnectionInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getConnections"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new ConnectionInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("ConnectionInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("ConnectionInfoList.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 + ConnectionInfoListPropertyDescriptor pd = new ConnectionInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class ConnectionInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private ConnectionInfo Item { get { return (ConnectionInfo) _Item;} } + public ConnectionInfoListPropertyDescriptor(ConnectionInfoList collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class ConnectionInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ConnectionInfoList) + { + // Return department and department role separated by comma. + return ((ConnectionInfoList) value).Items.Count.ToString() + " Connections"; + } + 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 new file mode 100644 index 00000000..50171743 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Content.cs @@ -0,0 +1,1410 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +using Csla.Validation; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Content tmp in _AllList) + { + _AllByPrimaryKey[tmp.ContentID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (Content tmp in remove) + _AllList.Remove(tmp); + } + public static Content GetExistingByPrimaryKey(int contentID) + { + ConvertListToDictionary(); + string key = contentID.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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 != value) + { + _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; } } + protected Content() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(ContentID.ToString()); + } + 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 = GetExistingByPrimaryKey(contentID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(contentID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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(); + _AllList.Add(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 + + +//// The following is a sample Extension File. You can use it to create ContentExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class Content +// { +// partial class ContentExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUserID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ContentDetail.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ContentDetail.cs new file mode 100644 index 00000000..8a6a9dae --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ContentDetail.cs @@ -0,0 +1,470 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +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 +} // Namespace + + +//// The following is a sample Extension File. You can use it to create ContentDetailExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class ContentDetail +// { +// partial class ContentDetailExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUserID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ContentDetails.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ContentDetails.cs new file mode 100644 index 00000000..72562d84 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ContentDetails.cs @@ -0,0 +1,290 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using Csla.Validation; +namespace VEPROMS.CSLA.Library +{ + /// + /// ContentDetails Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ContentDetailsConverter))] + public partial class ContentDetails : BusinessListBase, ICustomTypeDescriptor, 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; } + } + // One To Many + public ContentDetail this[Detail myDetail] + { + get + { + foreach (ContentDetail detail in this) + if (detail.DetailID == myDetail.DetailID) + return detail; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public ContentDetail GetItem(Detail myDetail) + { + foreach (ContentDetail detail in this) + if (detail.DetailID == myDetail.DetailID) + return detail; + return null; + } + public ContentDetail Add(int itemType, string text) // One to Many + { + ContentDetail detail = ContentDetail.New(itemType, text); + this.Add(detail); + return detail; + } + public void Remove(Detail myDetail) + { + foreach (ContentDetail detail in this) + { + if (detail.DetailID == myDetail.DetailID) + { + Remove(detail); + break; + } + } + } + public bool Contains(Detail myDetail) + { + foreach (ContentDetail detail in this) + if (detail.DetailID == myDetail.DetailID) + return true; + return false; + } + public bool ContainsDeleted(Detail myDetail) + { + foreach (ContentDetail detail in DeletedList) + if (detail.DetailID == myDetail.DetailID) + return true; + return false; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules=null; + foreach(ContentDetail contentDetail in this) + if ((hasBrokenRules = contentDetail.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static ContentDetails New() + { + return new ContentDetails(); + } + internal static ContentDetails Get(SafeDataReader dr) + { + return new ContentDetails(dr); + } + public static ContentDetails GetByContentID(int contentID) + { + try + { + return DataPortal.Fetch(new ContentIDCriteria(contentID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentDetails.GetByContentID", ex); + } + } + private ContentDetails() + { + MarkAsChild(); + } + internal ContentDetails(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(ContentDetail.Get(dr)); + 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}] ContentDetails.DataPortal_FetchContentID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDetailsByContentID"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new ContentDetail(dr)); + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("ContentDetails.DataPortal_FetchContentID", ex); + throw new DbCslaException("ContentDetails.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(Content content) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (ContentDetail obj in DeletedList) + obj.DeleteSelf(content);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (ContentDetail obj in this) + { + if (obj.IsNew) + obj.Insert(content); + else + obj.Update(content); + } + } + finally + { + 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 + ContentDetailsPropertyDescriptor pd = new ContentDetailsPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class ContentDetailsPropertyDescriptor : vlnListPropertyDescriptor + { + private ContentDetail Item { get { return (ContentDetail) _Item;} } + public ContentDetailsPropertyDescriptor(ContentDetails collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class ContentDetailsConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ContentDetails) + { + // Return department and department role separated by comma. + return ((ContentDetails) value).Items.Count.ToString() + " Details"; + } + 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 new file mode 100644 index 00000000..103559c6 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ContentInfo.cs @@ -0,0 +1,570 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (ContentInfo tmp in _AllList) + { + _AllByPrimaryKey[tmp.ContentID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (ContentInfo tmp in remove) + _AllList.Remove(tmp); + } + internal static void AddList(ContentInfoList lst) + { + foreach (ContentInfo item in lst) _AllList.Add(item); + } + public static ContentInfo GetExistingByPrimaryKey(int contentID) + { + ConvertListToDictionary(); + string key = contentID.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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 && _ContentDetails == null) + _ContentDetails = DetailInfoList.GetByContentID(_ContentID); + 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 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); + 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 && _ContentItems == null) + _ContentItems = ItemInfoList.GetByContentID(_ContentID); + 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 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 && _ContentParts == null) + _ContentParts = PartInfoList.GetByContentID(_ContentID); + 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 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 && _ContentRoUsages == null) + _ContentRoUsages = RoUsageInfoList.GetByContentID(_ContentID); + 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 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 && _ContentTransitions == null) + _ContentTransitions = TransitionInfoList.GetByFromID(_ContentID); + 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 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); + 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 ContentInfo() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(ContentID.ToString()); + } + public virtual Content Get() + { + return _Editable = Content.Get(_ContentID); + } + public static void Refresh(Content tmp) + { + ContentInfo tmpInfo = GetExistingByPrimaryKey(tmp.ContentID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(Content tmp) + { + _Number = tmp.Number; + _Text = tmp.Text; + _Type = tmp.Type; + _FormatID = tmp.FormatID; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _ContentInfoExtension.Refresh(this); + _MyFormat = null; + _MyEntry = null; + _MyZContent = null; + OnChange();// raise an event + } + public static void Refresh(FormatContent tmp) + { + ContentInfo tmpInfo = GetExistingByPrimaryKey(tmp.ContentID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private 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); + _MyFormat = null; + _MyEntry = null; + _MyZContent = null; + 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 = GetExistingByPrimaryKey(contentID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(contentID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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/Generated/ContentInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ContentInfoList.cs new file mode 100644 index 00000000..4322e6d4 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ContentInfoList.cs @@ -0,0 +1,255 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +namespace VEPROMS.CSLA.Library +{ + /// + /// ContentInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ContentInfoListConverter))] + public partial class ContentInfoList : 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 (ContentInfo tmp in this) + { + tmp.Changed += new ContentInfoEvent(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)); + } + } + public void Dispose() + { + foreach (ContentInfo tmp in this) + { + tmp.Changed -= new ContentInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static ContentInfoList _ContentInfoList = null; + /// + /// Return a list of all projects. + /// + public static ContentInfoList Get() + { + try + { + if (_ContentInfoList != null) + return _ContentInfoList; + ContentInfoList tmp = DataPortal.Fetch(); + ContentInfo.AddList(tmp); + tmp.AddEvents(); + _ContentInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentInfoList.Get", ex); + } + } + // TODO: Add alternative gets - + //public static ContentInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on ContentInfoList.Get", ex); + // } + //} + public static ContentInfoList GetByFormatID(int? formatID) + { + try + { + ContentInfoList tmp = DataPortal.Fetch(new FormatIDCriteria(formatID)); + ContentInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentInfoList.GetByFormatID", ex); + } + } + private ContentInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ContentInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getContents"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new ContentInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("ContentInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("ContentInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class FormatIDCriteria + { + public FormatIDCriteria(int? formatID) + { + _FormatID = formatID; + } + private int? _FormatID; + public int? FormatID + { + get { return _FormatID; } + set { _FormatID = value; } + } + } + private void DataPortal_Fetch(FormatIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ContentInfoList.DataPortal_FetchFormatID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getContentsByFormatID"; + cm.Parameters.AddWithValue("@FormatID", criteria.FormatID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new ContentInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("ContentInfoList.DataPortal_FetchFormatID", ex); + throw new DbCslaException("ContentInfoList.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 + ContentInfoListPropertyDescriptor pd = new ContentInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class ContentInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private ContentInfo Item { get { return (ContentInfo) _Item;} } + public ContentInfoListPropertyDescriptor(ContentInfoList collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class ContentInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ContentInfoList) + { + // Return department and department role separated by comma. + return ((ContentInfoList) value).Items.Count.ToString() + " Contents"; + } + 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 new file mode 100644 index 00000000..d1cad0f4 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ContentItem.cs @@ -0,0 +1,418 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +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 != value) + { + _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 +} // Namespace + + +//// The following is a sample Extension File. You can use it to create ContentItemExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class ContentItem +// { +// partial class ContentItemExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUserID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ContentItems.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ContentItems.cs new file mode 100644 index 00000000..0ba528a2 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ContentItems.cs @@ -0,0 +1,290 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using Csla.Validation; +namespace VEPROMS.CSLA.Library +{ + /// + /// ContentItems Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ContentItemsConverter))] + public partial class ContentItems : BusinessListBase, ICustomTypeDescriptor, 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; } + } + // One To Many + public ContentItem this[Item myItem] + { + get + { + foreach (ContentItem item in this) + if (item.ItemID == myItem.ItemID) + return item; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public ContentItem GetItem(Item myItem) + { + foreach (ContentItem item in this) + if (item.ItemID == myItem.ItemID) + return item; + return null; + } + public ContentItem Add() // One to Many + { + ContentItem item = ContentItem.New(); + this.Add(item); + return item; + } + public void Remove(Item myItem) + { + foreach (ContentItem item in this) + { + if (item.ItemID == myItem.ItemID) + { + Remove(item); + break; + } + } + } + public bool Contains(Item myItem) + { + foreach (ContentItem item in this) + if (item.ItemID == myItem.ItemID) + return true; + return false; + } + public bool ContainsDeleted(Item myItem) + { + foreach (ContentItem item in DeletedList) + if (item.ItemID == myItem.ItemID) + return true; + return false; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules=null; + foreach(ContentItem contentItem in this) + if ((hasBrokenRules = contentItem.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static ContentItems New() + { + return new ContentItems(); + } + internal static ContentItems Get(SafeDataReader dr) + { + return new ContentItems(dr); + } + public static ContentItems GetByContentID(int contentID) + { + try + { + return DataPortal.Fetch(new ContentIDCriteria(contentID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentItems.GetByContentID", ex); + } + } + private ContentItems() + { + MarkAsChild(); + } + internal ContentItems(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(ContentItem.Get(dr)); + 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}] ContentItems.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); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new ContentItem(dr)); + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("ContentItems.DataPortal_FetchContentID", ex); + throw new DbCslaException("ContentItems.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(Content content) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (ContentItem obj in DeletedList) + obj.DeleteSelf(content);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (ContentItem obj in this) + { + if (obj.IsNew) + obj.Insert(content); + else + obj.Update(content); + } + } + finally + { + 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 + ContentItemsPropertyDescriptor pd = new ContentItemsPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class ContentItemsPropertyDescriptor : vlnListPropertyDescriptor + { + private ContentItem Item { get { return (ContentItem) _Item;} } + public ContentItemsPropertyDescriptor(ContentItems collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class ContentItemsConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ContentItems) + { + // Return department and department role separated by comma. + return ((ContentItems) value).Items.Count.ToString() + " Items"; + } + 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 new file mode 100644 index 00000000..e4eb1f15 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ContentPart.cs @@ -0,0 +1,476 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +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(); + + _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 + + +//// The following is a sample Extension File. You can use it to create ContentPartExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class ContentPart +// { +// partial class ContentPartExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUserID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ContentParts.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ContentParts.cs new file mode 100644 index 00000000..9c9997d7 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ContentParts.cs @@ -0,0 +1,295 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using Csla.Validation; +namespace VEPROMS.CSLA.Library +{ + /// + /// ContentParts Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ContentPartsConverter))] + public partial class ContentParts : BusinessListBase, ICustomTypeDescriptor, 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; } + } + // One To Many + public new ContentPart this[int fromType] + { + get + { + foreach (ContentPart part in this) + if (part.FromType == fromType) + return part; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public ContentPart GetItem(int fromType) + { + foreach (ContentPart part in this) + if (part.FromType == fromType) + return part; + return null; + } + public ContentPart Add(int fromType, Item myItem) // One to Many with unique fields + { + if (!Contains(fromType)) + { + ContentPart part = ContentPart.New(fromType, myItem); + this.Add(part); + return part; + } + else + throw new InvalidOperationException("part already exists"); + } + public void Remove(int fromType) + { + foreach (ContentPart part in this) + { + if (part.FromType == fromType) + { + Remove(part); + break; + } + } + } + public bool Contains(int fromType) + { + foreach (ContentPart part in this) + if (part.FromType == fromType) + return true; + return false; + } + public bool ContainsDeleted(int fromType) + { + foreach (ContentPart part in DeletedList) + if (part.FromType == fromType) + return true; + return false; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules=null; + foreach(ContentPart contentPart in this) + if ((hasBrokenRules = contentPart.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static ContentParts New() + { + return new ContentParts(); + } + internal static ContentParts Get(SafeDataReader dr) + { + return new ContentParts(dr); + } + public static ContentParts GetByContentID(int contentID) + { + try + { + return DataPortal.Fetch(new ContentIDCriteria(contentID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentParts.GetByContentID", ex); + } + } + private ContentParts() + { + MarkAsChild(); + } + internal ContentParts(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(ContentPart.Get(dr)); + 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}] ContentParts.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); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new ContentPart(dr)); + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("ContentParts.DataPortal_FetchContentID", ex); + throw new DbCslaException("ContentParts.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(Content content) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (ContentPart obj in DeletedList) + obj.DeleteSelf(content);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (ContentPart obj in this) + { + if (obj.IsNew) + obj.Insert(content); + else + obj.Update(content); + } + } + finally + { + 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 + ContentPartsPropertyDescriptor pd = new ContentPartsPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class ContentPartsPropertyDescriptor : vlnListPropertyDescriptor + { + private ContentPart Item { get { return (ContentPart) _Item;} } + public ContentPartsPropertyDescriptor(ContentParts collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class ContentPartsConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ContentParts) + { + // Return department and department role separated by comma. + return ((ContentParts) value).Items.Count.ToString() + " Parts"; + } + 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 new file mode 100644 index 00000000..c7fb1daa --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ContentRoUsage.cs @@ -0,0 +1,454 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +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 + // 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(); + //} + #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, "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 + } + // Sample data comparison validation rule + //private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e) + //{ + // if (_started > _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, ""); + } + 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) + { + return new ContentRoUsage(roid); + } + 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) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _DTS = _ContentRoUsageExtension.DefaultDTS; + _UserID = _ContentRoUsageExtension.DefaultUserID; + _ROID = roid; + 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); + } + 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); + 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); + 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 + + +//// The following is a sample Extension File. You can use it to create ContentRoUsageExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class ContentRoUsage +// { +// partial class ContentRoUsageExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual int DefaultContentID +// { +// get { return 0; } +// } +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUserID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ContentRoUsages.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ContentRoUsages.cs new file mode 100644 index 00000000..bc74a8e2 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ContentRoUsages.cs @@ -0,0 +1,290 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using Csla.Validation; +namespace VEPROMS.CSLA.Library +{ + /// + /// ContentRoUsages Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ContentRoUsagesConverter))] + public partial class ContentRoUsages : BusinessListBase, ICustomTypeDescriptor, 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; } + } + // One To Many + public ContentRoUsage this[RoUsage myRoUsage] + { + get + { + foreach (ContentRoUsage roUsage in this) + if (roUsage.ROUsageID == myRoUsage.ROUsageID) + return roUsage; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public ContentRoUsage GetItem(RoUsage myRoUsage) + { + foreach (ContentRoUsage roUsage in this) + if (roUsage.ROUsageID == myRoUsage.ROUsageID) + return roUsage; + return null; + } + public ContentRoUsage Add(string roid) // One to Many + { + ContentRoUsage roUsage = ContentRoUsage.New(roid); + this.Add(roUsage); + return roUsage; + } + public void Remove(RoUsage myRoUsage) + { + foreach (ContentRoUsage roUsage in this) + { + if (roUsage.ROUsageID == myRoUsage.ROUsageID) + { + Remove(roUsage); + break; + } + } + } + public bool Contains(RoUsage myRoUsage) + { + foreach (ContentRoUsage roUsage in this) + if (roUsage.ROUsageID == myRoUsage.ROUsageID) + return true; + return false; + } + public bool ContainsDeleted(RoUsage myRoUsage) + { + foreach (ContentRoUsage roUsage in DeletedList) + if (roUsage.ROUsageID == myRoUsage.ROUsageID) + return true; + return false; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules=null; + foreach(ContentRoUsage contentRoUsage in this) + if ((hasBrokenRules = contentRoUsage.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static ContentRoUsages New() + { + return new ContentRoUsages(); + } + internal static ContentRoUsages Get(SafeDataReader dr) + { + return new ContentRoUsages(dr); + } + public static ContentRoUsages GetByContentID(int contentID) + { + try + { + return DataPortal.Fetch(new ContentIDCriteria(contentID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentRoUsages.GetByContentID", ex); + } + } + private ContentRoUsages() + { + MarkAsChild(); + } + internal ContentRoUsages(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(ContentRoUsage.Get(dr)); + 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}] ContentRoUsages.DataPortal_FetchContentID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getRoUsagesByContentID"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new ContentRoUsage(dr)); + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("ContentRoUsages.DataPortal_FetchContentID", ex); + throw new DbCslaException("ContentRoUsages.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(Content content) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (ContentRoUsage obj in DeletedList) + obj.DeleteSelf(content);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (ContentRoUsage obj in this) + { + if (obj.IsNew) + obj.Insert(content); + else + obj.Update(content); + } + } + finally + { + 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 + ContentRoUsagesPropertyDescriptor pd = new ContentRoUsagesPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class ContentRoUsagesPropertyDescriptor : vlnListPropertyDescriptor + { + private ContentRoUsage Item { get { return (ContentRoUsage) _Item;} } + public ContentRoUsagesPropertyDescriptor(ContentRoUsages collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class ContentRoUsagesConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ContentRoUsages) + { + // Return department and department role separated by comma. + return ((ContentRoUsages) value).Items.Count.ToString() + " RoUsages"; + } + 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 new file mode 100644 index 00000000..ad9ec76d --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ContentTransition.cs @@ -0,0 +1,642 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +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 +} // Namespace + + +//// The following is a sample Extension File. You can use it to create ContentTransitionExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class ContentTransition +// { +// partial class ContentTransitionExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual int DefaultTranType +// { +// get { return 0; } +// } +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUserID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ContentTransitions.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ContentTransitions.cs new file mode 100644 index 00000000..646f20d1 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ContentTransitions.cs @@ -0,0 +1,290 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using Csla.Validation; +namespace VEPROMS.CSLA.Library +{ + /// + /// ContentTransitions Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ContentTransitionsConverter))] + public partial class ContentTransitions : BusinessListBase, ICustomTypeDescriptor, 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; } + } + // One To Many + public ContentTransition this[Transition myTransition] + { + get + { + foreach (ContentTransition transition in this) + if (transition.TransitionID == myTransition.TransitionID) + return transition; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public ContentTransition GetItem(Transition myTransition) + { + foreach (ContentTransition transition in this) + if (transition.TransitionID == myTransition.TransitionID) + return transition; + return null; + } + public ContentTransition Add(Item myItemToID, Item myItemRangeID) // One to Many + { + ContentTransition transition = ContentTransition.New(myItemToID, myItemRangeID); + this.Add(transition); + return transition; + } + public void Remove(Transition myTransition) + { + foreach (ContentTransition transition in this) + { + if (transition.TransitionID == myTransition.TransitionID) + { + Remove(transition); + break; + } + } + } + public bool Contains(Transition myTransition) + { + foreach (ContentTransition transition in this) + if (transition.TransitionID == myTransition.TransitionID) + return true; + return false; + } + public bool ContainsDeleted(Transition myTransition) + { + foreach (ContentTransition transition in DeletedList) + if (transition.TransitionID == myTransition.TransitionID) + return true; + return false; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules=null; + foreach(ContentTransition contentTransition in this) + if ((hasBrokenRules = contentTransition.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static ContentTransitions New() + { + return new ContentTransitions(); + } + internal static ContentTransitions Get(SafeDataReader dr) + { + return new ContentTransitions(dr); + } + public static ContentTransitions GetByFromID(int fromID) + { + try + { + return DataPortal.Fetch(new FromIDCriteria(fromID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentTransitions.GetByFromID", ex); + } + } + private ContentTransitions() + { + MarkAsChild(); + } + internal ContentTransitions(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(ContentTransition.Get(dr)); + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class FromIDCriteria + { + public FromIDCriteria(int fromID) + { + _FromID = fromID; + } + private int _FromID; + public int FromID + { + get { return _FromID; } + set { _FromID = value; } + } + } + private void DataPortal_Fetch(FromIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ContentTransitions.DataPortal_FetchFromID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getTransitionsByFromID"; + cm.Parameters.AddWithValue("@FromID", criteria.FromID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new ContentTransition(dr)); + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("ContentTransitions.DataPortal_FetchFromID", ex); + throw new DbCslaException("ContentTransitions.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(Content content) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (ContentTransition obj in DeletedList) + obj.DeleteSelf(content);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (ContentTransition obj in this) + { + if (obj.IsNew) + obj.Insert(content); + else + obj.Update(content); + } + } + finally + { + 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 + ContentTransitionsPropertyDescriptor pd = new ContentTransitionsPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class ContentTransitionsPropertyDescriptor : vlnListPropertyDescriptor + { + private ContentTransition Item { get { return (ContentTransition) _Item;} } + public ContentTransitionsPropertyDescriptor(ContentTransitions collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class ContentTransitionsConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ContentTransitions) + { + // Return department and department role separated by comma. + return ((ContentTransitions) value).Items.Count.ToString() + " Transitions"; + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Database.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Database.cs new file mode 100644 index 00000000..aed9e75a --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Database.cs @@ -0,0 +1,138 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Diagnostics; +namespace VEPROMS.CSLA.Library +{ + /// + /// Database Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + public static partial class Database + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + public static void LogException(string s,Exception ex) + { + int i = 0; + Console.WriteLine("Error - {0}", s); + for (; ex != null; ex = ex.InnerException) + { + Console.WriteLine("{0}{1} - {2}", "".PadLeft(++i * 2), ex.GetType().ToString(), ex.Message); + } + } + private static bool _LoggingInfo = false; // By default don't log info + public static bool LoggingInfo + { + get { return _LoggingInfo; } + set { _LoggingInfo = value; } + } + static System.Diagnostics.Process _CurrentProcess = System.Diagnostics.Process.GetCurrentProcess(); + public static void LogInfo(string s,int hashCode) + { + if (_LoggingInfo) + Console.WriteLine("{0} MB {1}", _CurrentProcess.WorkingSet64 / 1000000, string.Format(s, hashCode)); + } + public static void LogDebug(string s,int hashCode) + { + if (_LoggingInfo) + Console.WriteLine("{0} MB {1}", _CurrentProcess.WorkingSet64 / 1000000, string.Format(s, hashCode)); + } + public static string VEPROMS_Connection + { + get + { + DateTime.Today.ToLongDateString(); + ConnectionStringSettings cs = ConfigurationManager.ConnectionStrings["VEPROMS"]; + if (cs == null) + { + throw new ApplicationException("Database.cs Could not find connection VEPROMS"); + } + return cs.ConnectionString; + } + } + public static SqlConnection VEPROMS_SqlConnection + { + get + { + string strConn = VEPROMS_Connection; // If failure - Fail (Don't try to catch) + // Attempt to make a connection + try + { + SqlConnection cn = new SqlConnection(strConn); + cn.Open(); + return cn; + } + catch (SqlException exsql) + { + const string strAttachError = "An attempt to attach an auto-named database for file "; + if (exsql.Message.StartsWith(strAttachError)) + {// Check to see if the file is missing + string sFile = exsql.Message.Substring(strAttachError.Length); + sFile = sFile.Substring(0, sFile.IndexOf(" failed")); + // "An attempt to attach an auto-named database for file failed" + if (strConn.ToLower().IndexOf("user instance=true") < 0) + { + throw new ApplicationException("Connection String missing attribute: User Instance=True"); + } + if (System.IO.File.Exists(sFile)) + { + throw new ApplicationException("Database file " + sFile + " Cannot be opened\r\n", exsql); + } + else + { + throw new FileNotFoundException("Database file " + sFile + " Not Found", exsql); + } + } + else + { + throw new ApplicationException("Failure on Connect", exsql); + } + } + catch (Exception ex)// Throw Application Exception on Failure + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("Connection Error", ex); + throw new ApplicationException("Failure on Connect", ex); + } + } + } + public static void PurgeData() + { + try + { + SqlConnection cn = VEPROMS_SqlConnection; + SqlCommand cmd = new SqlCommand("purgedata", cn); + cmd.CommandType = CommandType.StoredProcedure; + cmd.CommandTimeout = 0; + cmd.ExecuteNonQuery(); + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("Purge Error", ex); + throw new ApplicationException("Failure on Purge", ex); + } + } + } + public class DbCslaException : Exception + { + internal DbCslaException(string message, Exception innerException):base(message,innerException){;} + internal DbCslaException(string message) : base(message) { ;} + internal DbCslaException() : base() { ;} + } // Class +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Detail.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Detail.cs new file mode 100644 index 00000000..d4283559 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Detail.cs @@ -0,0 +1,1042 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +using Csla.Validation; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Detail tmp in _AllList) + { + _AllByPrimaryKey[tmp.DetailID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (Detail tmp in remove) + _AllList.Remove(tmp); + } + public static Detail GetExistingByPrimaryKey(int detailID) + { + ConvertListToDictionary(); + string key = detailID.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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; } } + protected Detail() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(DetailID.ToString()); + } + 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 = GetExistingByPrimaryKey(detailID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(detailID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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(); + _AllList.Add(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 + + +//// The following is a sample Extension File. You can use it to create DetailExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class Detail +// { +// partial class DetailExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUserID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DetailInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DetailInfo.cs new file mode 100644 index 00000000..ce06b98e --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DetailInfo.cs @@ -0,0 +1,361 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (DetailInfo tmp in _AllList) + { + _AllByPrimaryKey[tmp.DetailID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (DetailInfo tmp in remove) + _AllList.Remove(tmp); + } + internal static void AddList(DetailInfoList lst) + { + foreach (DetailInfo item in lst) _AllList.Add(item); + } + public static DetailInfo GetExistingByPrimaryKey(int detailID) + { + ConvertListToDictionary(); + string key = detailID.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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 DetailInfo() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(DetailID.ToString()); + } + public virtual Detail Get() + { + return _Editable = Detail.Get(_DetailID); + } + public static void Refresh(Detail tmp) + { + DetailInfo tmpInfo = GetExistingByPrimaryKey(tmp.DetailID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(Detail tmp) + { + _ContentID = tmp.ContentID; + _ItemType = tmp.ItemType; + _Text = tmp.Text; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DetailInfoExtension.Refresh(this); + _MyContent = null; + OnChange();// raise an event + } + public static void Refresh(ContentDetail tmp) + { + DetailInfo tmpInfo = GetExistingByPrimaryKey(tmp.DetailID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(ContentDetail tmp) + { + _ItemType = tmp.ItemType; + _Text = tmp.Text; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DetailInfoExtension.Refresh(this); + _MyContent = null; + 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 = GetExistingByPrimaryKey(detailID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(detailID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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/Generated/DetailInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DetailInfoList.cs new file mode 100644 index 00000000..2645ac83 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DetailInfoList.cs @@ -0,0 +1,255 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +namespace VEPROMS.CSLA.Library +{ + /// + /// DetailInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DetailInfoListConverter))] + public partial class DetailInfoList : 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 (DetailInfo tmp in this) + { + tmp.Changed += new DetailInfoEvent(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)); + } + } + public void Dispose() + { + foreach (DetailInfo tmp in this) + { + tmp.Changed -= new DetailInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static DetailInfoList _DetailInfoList = null; + /// + /// Return a list of all projects. + /// + public static DetailInfoList Get() + { + try + { + if (_DetailInfoList != null) + return _DetailInfoList; + DetailInfoList tmp = DataPortal.Fetch(); + DetailInfo.AddList(tmp); + tmp.AddEvents(); + _DetailInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DetailInfoList.Get", ex); + } + } + // TODO: Add alternative gets - + //public static DetailInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on DetailInfoList.Get", ex); + // } + //} + public static DetailInfoList GetByContentID(int contentID) + { + try + { + DetailInfoList tmp = DataPortal.Fetch(new ContentIDCriteria(contentID)); + DetailInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DetailInfoList.GetByContentID", ex); + } + } + private DetailInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] DetailInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDetails"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new DetailInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("DetailInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("DetailInfoList.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}] DetailInfoList.DataPortal_FetchContentID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDetailsByContentID"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new DetailInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("DetailInfoList.DataPortal_FetchContentID", ex); + throw new DbCslaException("DetailInfoList.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 + DetailInfoListPropertyDescriptor pd = new DetailInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class DetailInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private DetailInfo Item { get { return (DetailInfo) _Item;} } + public DetailInfoListPropertyDescriptor(DetailInfoList collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class DetailInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is DetailInfoList) + { + // Return department and department role separated by comma. + return ((DetailInfoList) value).Items.Count.ToString() + " Details"; + } + 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 new file mode 100644 index 00000000..6d74f55a --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocVersion.cs @@ -0,0 +1,1177 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +using Csla.Validation; +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 void AddToRefreshList(List refreshDocVersions) + { + if (IsDirty) + refreshDocVersions.Add(this); + } + private void BuildRefreshList() + { + _RefreshDocVersions = new List(); + AddToRefreshList(_RefreshDocVersions); + } + 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); + } + } + #endregion + #region Collection + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (DocVersion tmp in _AllList) + { + _AllByPrimaryKey[tmp.VersionID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (DocVersion tmp in remove) + _AllList.Remove(tmp); + } + public static DocVersion GetExistingByPrimaryKey(int versionID) + { + ConvertListToDictionary(); + string key = versionID.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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 != value) + { + _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 != value) + { + _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 override bool IsDirty + { + get { return base.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) && (_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 (_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; + } + 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; } } + protected DocVersion() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(VersionID.ToString()); + } + 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 = GetExistingByPrimaryKey(versionID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(versionID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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(); + _AllList.Add(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); + 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); + } + } + // removing of item 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(_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 + } + 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(); + } + } + [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 + + +//// The following is a sample Extension File. You can use it to create DocVersionExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class DocVersion +// { +// partial class DocVersionExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual int DefaultVersionType +// { +// get { return 0; } +// } +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUserID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionInfo.cs new file mode 100644 index 00000000..5cca3041 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionInfo.cs @@ -0,0 +1,475 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (DocVersionInfo tmp in _AllList) + { + _AllByPrimaryKey[tmp.VersionID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (DocVersionInfo tmp in remove) + _AllList.Remove(tmp); + } + internal static void AddList(DocVersionInfoList lst) + { + foreach (DocVersionInfo item in lst) _AllList.Add(item); + } + public static DocVersionInfo GetExistingByPrimaryKey(int versionID) + { + ConvertListToDictionary(); + string key = versionID.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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; + } + } + // 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 DocVersionInfo() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(VersionID.ToString()); + } + public virtual DocVersion Get() + { + return _Editable = DocVersion.Get(_VersionID); + } + public static void Refresh(DocVersion tmp) + { + DocVersionInfo tmpInfo = GetExistingByPrimaryKey(tmp.VersionID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(DocVersion tmp) + { + _FolderID = tmp.FolderID; + _VersionType = tmp.VersionType; + _Name = tmp.Name; + _Title = tmp.Title; + _ItemID = tmp.ItemID; + _FormatID = tmp.FormatID; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DocVersionInfoExtension.Refresh(this); + _MyFolder = null; + _MyItem = null; + _MyFormat = null; + OnChange();// raise an event + } + public static void Refresh(FolderDocVersion tmp) + { + DocVersionInfo tmpInfo = GetExistingByPrimaryKey(tmp.VersionID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(FolderDocVersion tmp) + { + _VersionType = tmp.VersionType; + _Name = tmp.Name; + _Title = tmp.Title; + _ItemID = tmp.ItemID; + _FormatID = tmp.FormatID; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DocVersionInfoExtension.Refresh(this); + _MyFolder = null; + _MyItem = null; + _MyFormat = null; + OnChange();// raise an event + } + public static void Refresh(FormatDocVersion tmp) + { + DocVersionInfo tmpInfo = GetExistingByPrimaryKey(tmp.VersionID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(FormatDocVersion tmp) + { + _FolderID = tmp.FolderID; + _VersionType = tmp.VersionType; + _Name = tmp.Name; + _Title = tmp.Title; + _ItemID = tmp.ItemID; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DocVersionInfoExtension.Refresh(this); + _MyFolder = null; + _MyItem = null; + _MyFormat = null; + OnChange();// raise an event + } + public static void Refresh(ItemDocVersion tmp) + { + DocVersionInfo tmpInfo = GetExistingByPrimaryKey(tmp.VersionID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(ItemDocVersion tmp) + { + _FolderID = tmp.FolderID; + _VersionType = tmp.VersionType; + _Name = tmp.Name; + _Title = tmp.Title; + _FormatID = tmp.FormatID; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DocVersionInfoExtension.Refresh(this); + _MyFolder = null; + _MyItem = null; + _MyFormat = null; + 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 = GetExistingByPrimaryKey(versionID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(versionID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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"); + } + 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/Generated/DocVersionInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionInfoList.cs new file mode 100644 index 00000000..79331617 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionInfoList.cs @@ -0,0 +1,369 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +namespace VEPROMS.CSLA.Library +{ + /// + /// DocVersionInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DocVersionInfoListConverter))] + public partial class DocVersionInfoList : 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 (DocVersionInfo tmp in this) + { + tmp.Changed += new DocVersionInfoEvent(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)); + } + } + public void Dispose() + { + foreach (DocVersionInfo tmp in this) + { + tmp.Changed -= new DocVersionInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static DocVersionInfoList _DocVersionInfoList = null; + /// + /// Return a list of all projects. + /// + public static DocVersionInfoList Get() + { + try + { + if (_DocVersionInfoList != null) + return _DocVersionInfoList; + DocVersionInfoList tmp = DataPortal.Fetch(); + DocVersionInfo.AddList(tmp); + tmp.AddEvents(); + _DocVersionInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocVersionInfoList.Get", ex); + } + } + // TODO: Add alternative gets - + //public static DocVersionInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on DocVersionInfoList.Get", ex); + // } + //} + public static DocVersionInfoList GetByFolderID(int folderID) + { + try + { + DocVersionInfoList tmp = DataPortal.Fetch(new FolderIDCriteria(folderID)); + DocVersionInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocVersionInfoList.GetByFolderID", ex); + } + } + public static DocVersionInfoList GetByFormatID(int? formatID) + { + try + { + DocVersionInfoList tmp = DataPortal.Fetch(new FormatIDCriteria(formatID)); + DocVersionInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocVersionInfoList.GetByFormatID", ex); + } + } + public static DocVersionInfoList GetByItemID(int? itemID) + { + try + { + DocVersionInfoList tmp = DataPortal.Fetch(new ItemIDCriteria(itemID)); + DocVersionInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocVersionInfoList.GetByItemID", ex); + } + } + private DocVersionInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] DocVersionInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDocVersions"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new DocVersionInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("DocVersionInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("DocVersionInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class FolderIDCriteria + { + public FolderIDCriteria(int folderID) + { + _FolderID = folderID; + } + private int _FolderID; + public int FolderID + { + get { return _FolderID; } + set { _FolderID = value; } + } + } + private void DataPortal_Fetch(FolderIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] DocVersionInfoList.DataPortal_FetchFolderID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDocVersionsByFolderID"; + cm.Parameters.AddWithValue("@FolderID", criteria.FolderID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new DocVersionInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("DocVersionInfoList.DataPortal_FetchFolderID", ex); + throw new DbCslaException("DocVersionInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class FormatIDCriteria + { + public FormatIDCriteria(int? formatID) + { + _FormatID = formatID; + } + private int? _FormatID; + public int? FormatID + { + get { return _FormatID; } + set { _FormatID = value; } + } + } + private void DataPortal_Fetch(FormatIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] DocVersionInfoList.DataPortal_FetchFormatID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDocVersionsByFormatID"; + cm.Parameters.AddWithValue("@FormatID", criteria.FormatID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new DocVersionInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("DocVersionInfoList.DataPortal_FetchFormatID", ex); + throw new DbCslaException("DocVersionInfoList.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}] DocVersionInfoList.DataPortal_FetchItemID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDocVersionsByItemID"; + cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new DocVersionInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("DocVersionInfoList.DataPortal_FetchItemID", ex); + throw new DbCslaException("DocVersionInfoList.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 + DocVersionInfoListPropertyDescriptor pd = new DocVersionInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class DocVersionInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private DocVersionInfo Item { get { return (DocVersionInfo) _Item;} } + public DocVersionInfoListPropertyDescriptor(DocVersionInfoList collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class DocVersionInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is DocVersionInfoList) + { + // Return department and department role separated by comma. + return ((DocVersionInfoList) value).Items.Count.ToString() + " DocVersions"; + } + 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 new file mode 100644 index 00000000..2a2cfd80 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Document.cs @@ -0,0 +1,1081 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +using Csla.Validation; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Document tmp in _AllList) + { + _AllByPrimaryKey[tmp.DocID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (Document tmp in remove) + _AllList.Remove(tmp); + } + public static Document GetExistingByPrimaryKey(int docID) + { + ConvertListToDictionary(); + string key = docID.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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; } } + protected Document() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(DocID.ToString()); + } + 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) + 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) + { + 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) + 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 = GetExistingByPrimaryKey(docID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(docID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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(); + _AllList.Add(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 + + +//// The following is a sample Extension File. You can use it to create DocumentExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class Document +// { +// partial class DocumentExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUserID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentEntries.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentEntries.cs new file mode 100644 index 00000000..351ec4bf --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentEntries.cs @@ -0,0 +1,290 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using Csla.Validation; +namespace VEPROMS.CSLA.Library +{ + /// + /// DocumentEntries Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DocumentEntriesConverter))] + public partial class DocumentEntries : BusinessListBase, ICustomTypeDescriptor, 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; } + } + // One To Many + public DocumentEntry this[Entry myEntry] + { + get + { + foreach (DocumentEntry entry in this) + if (entry.ContentID == myEntry.ContentID) + return entry; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public DocumentEntry GetItem(Entry myEntry) + { + foreach (DocumentEntry entry in this) + if (entry.ContentID == myEntry.ContentID) + return entry; + return null; + } + public DocumentEntry Add(Entry myEntry) // One to Many + { + DocumentEntry entry = DocumentEntry.New(myEntry); + this.Add(entry); + return entry; + } + public void Remove(Entry myEntry) + { + foreach (DocumentEntry entry in this) + { + if (entry.ContentID == myEntry.ContentID) + { + Remove(entry); + break; + } + } + } + public bool Contains(Entry myEntry) + { + foreach (DocumentEntry entry in this) + if (entry.ContentID == myEntry.ContentID) + return true; + return false; + } + public bool ContainsDeleted(Entry myEntry) + { + foreach (DocumentEntry entry in DeletedList) + if (entry.ContentID == myEntry.ContentID) + return true; + return false; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules=null; + foreach(DocumentEntry documentEntry in this) + if ((hasBrokenRules = documentEntry.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static DocumentEntries New() + { + return new DocumentEntries(); + } + internal static DocumentEntries Get(SafeDataReader dr) + { + return new DocumentEntries(dr); + } + public static DocumentEntries GetByDocID(int docID) + { + try + { + return DataPortal.Fetch(new DocIDCriteria(docID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocumentEntries.GetByDocID", ex); + } + } + private DocumentEntries() + { + MarkAsChild(); + } + internal DocumentEntries(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(DocumentEntry.Get(dr)); + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class DocIDCriteria + { + public DocIDCriteria(int docID) + { + _DocID = docID; + } + private int _DocID; + public int DocID + { + get { return _DocID; } + set { _DocID = value; } + } + } + private void DataPortal_Fetch(DocIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] DocumentEntries.DataPortal_FetchDocID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getEntriesByDocID"; + cm.Parameters.AddWithValue("@DocID", criteria.DocID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new DocumentEntry(dr)); + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("DocumentEntries.DataPortal_FetchDocID", ex); + throw new DbCslaException("DocumentEntries.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(Document document) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (DocumentEntry obj in DeletedList) + obj.DeleteSelf(document);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (DocumentEntry obj in this) + { + if (obj.IsNew) + obj.Insert(document); + else + obj.Update(document); + } + } + finally + { + 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 + DocumentEntriesPropertyDescriptor pd = new DocumentEntriesPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class DocumentEntriesPropertyDescriptor : vlnListPropertyDescriptor + { + private DocumentEntry Item { get { return (DocumentEntry) _Item;} } + public DocumentEntriesPropertyDescriptor(DocumentEntries collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class DocumentEntriesConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is DocumentEntries) + { + // Return department and department role separated by comma. + return ((DocumentEntries) value).Items.Count.ToString() + " Entries"; + } + 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 new file mode 100644 index 00000000..3d48b588 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentEntry.cs @@ -0,0 +1,470 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +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(); + + _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 + + +//// The following is a sample Extension File. You can use it to create DocumentEntryExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class DocumentEntry +// { +// partial class DocumentEntryExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUserID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentInfo.cs new file mode 100644 index 00000000..7096c8da --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentInfo.cs @@ -0,0 +1,364 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (DocumentInfo tmp in _AllList) + { + _AllByPrimaryKey[tmp.DocID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (DocumentInfo tmp in remove) + _AllList.Remove(tmp); + } + internal static void AddList(DocumentInfoList lst) + { + foreach (DocumentInfo item in lst) _AllList.Add(item); + } + public static DocumentInfo GetExistingByPrimaryKey(int docID) + { + ConvertListToDictionary(); + string key = docID.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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 && _DocumentEntries == null) + _DocumentEntries = EntryInfoList.GetByDocID(_DocID); + return _DocumentEntries; + } + } + // 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 DocumentInfo() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(DocID.ToString()); + } + public virtual Document Get() + { + return _Editable = Document.Get(_DocID); + } + public static void Refresh(Document tmp) + { + DocumentInfo tmpInfo = GetExistingByPrimaryKey(tmp.DocID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private 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 = GetExistingByPrimaryKey(docID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(docID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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/Generated/DocumentInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentInfoList.cs new file mode 100644 index 00000000..d3515290 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentInfoList.cs @@ -0,0 +1,198 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +namespace VEPROMS.CSLA.Library +{ + /// + /// DocumentInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DocumentInfoListConverter))] + public partial class DocumentInfoList : 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 (DocumentInfo tmp in this) + { + tmp.Changed += new DocumentInfoEvent(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)); + } + } + public void Dispose() + { + foreach (DocumentInfo tmp in this) + { + tmp.Changed -= new DocumentInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static DocumentInfoList _DocumentInfoList = null; + /// + /// Return a list of all projects. + /// + public static DocumentInfoList Get() + { + try + { + if (_DocumentInfoList != null) + return _DocumentInfoList; + DocumentInfoList tmp = DataPortal.Fetch(); + DocumentInfo.AddList(tmp); + tmp.AddEvents(); + _DocumentInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocumentInfoList.Get", ex); + } + } + // TODO: Add alternative gets - + //public static DocumentInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on DocumentInfoList.Get", ex); + // } + //} + private DocumentInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] DocumentInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDocuments"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new DocumentInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("DocumentInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("DocumentInfoList.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 + DocumentInfoListPropertyDescriptor pd = new DocumentInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class DocumentInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private DocumentInfo Item { get { return (DocumentInfo) _Item;} } + public DocumentInfoListPropertyDescriptor(DocumentInfoList collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class DocumentInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is DocumentInfoList) + { + // Return department and department role separated by comma. + return ((DocumentInfoList) value).Items.Count.ToString() + " Documents"; + } + 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 new file mode 100644 index 00000000..21241569 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Entry.cs @@ -0,0 +1,933 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +using Csla.Validation; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Entry tmp in _AllList) + { + _AllByPrimaryKey[tmp.ContentID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (Entry tmp in remove) + _AllList.Remove(tmp); + } + public static Entry GetExistingByPrimaryKey(int contentID) + { + ConvertListToDictionary(); + string key = contentID.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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; } } + protected Entry() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(ContentID.ToString()); + } + 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 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 = GetExistingByPrimaryKey(contentID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(contentID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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(); + _AllList.Add(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 +} // Namespace + + +//// The following is a sample Extension File. You can use it to create EntryExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class Entry +// { +// partial class EntryExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUserID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/EntryInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/EntryInfo.cs new file mode 100644 index 00000000..495193b2 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/EntryInfo.cs @@ -0,0 +1,340 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (EntryInfo tmp in _AllList) + { + _AllByPrimaryKey[tmp.ContentID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (EntryInfo tmp in remove) + _AllList.Remove(tmp); + } + internal static void AddList(EntryInfoList lst) + { + foreach (EntryInfo item in lst) _AllList.Add(item); + } + public static EntryInfo GetExistingByPrimaryKey(int contentID) + { + ConvertListToDictionary(); + string key = contentID.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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 EntryInfo() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(ContentID.ToString()); + } + public virtual Entry Get() + { + return _Editable = Entry.Get(_ContentID); + } + public static void Refresh(Entry tmp) + { + EntryInfo tmpInfo = GetExistingByPrimaryKey(tmp.ContentID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(Entry tmp) + { + _DocID = tmp.DocID; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _EntryInfoExtension.Refresh(this); + _MyContent = null; + _MyDocument = null; + OnChange();// raise an event + } + public static void Refresh(DocumentEntry tmp) + { + EntryInfo tmpInfo = GetExistingByPrimaryKey(tmp.ContentID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(DocumentEntry tmp) + { + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _EntryInfoExtension.Refresh(this); + _MyContent = null; + _MyDocument = null; + 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 = GetExistingByPrimaryKey(contentID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(contentID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp._ContentID = contentID; + } + 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/Generated/EntryInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/EntryInfoList.cs new file mode 100644 index 00000000..f0dbeff7 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/EntryInfoList.cs @@ -0,0 +1,312 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +namespace VEPROMS.CSLA.Library +{ + /// + /// EntryInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(EntryInfoListConverter))] + public partial class EntryInfoList : 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 (EntryInfo tmp in this) + { + tmp.Changed += new EntryInfoEvent(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)); + } + } + public void Dispose() + { + foreach (EntryInfo tmp in this) + { + tmp.Changed -= new EntryInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static EntryInfoList _EntryInfoList = null; + /// + /// Return a list of all projects. + /// + public static EntryInfoList Get() + { + try + { + if (_EntryInfoList != null) + return _EntryInfoList; + EntryInfoList tmp = DataPortal.Fetch(); + EntryInfo.AddList(tmp); + tmp.AddEvents(); + _EntryInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on EntryInfoList.Get", ex); + } + } + // TODO: Add alternative gets - + //public static EntryInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on EntryInfoList.Get", ex); + // } + //} + public static EntryInfoList GetByContentID(int contentID) + { + try + { + EntryInfoList tmp = DataPortal.Fetch(new ContentIDCriteria(contentID)); + EntryInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on EntryInfoList.GetByContentID", ex); + } + } + public static EntryInfoList GetByDocID(int docID) + { + try + { + EntryInfoList tmp = DataPortal.Fetch(new DocIDCriteria(docID)); + EntryInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on EntryInfoList.GetByDocID", ex); + } + } + private EntryInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] EntryInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getEntries"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new EntryInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("EntryInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("EntryInfoList.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}] EntryInfoList.DataPortal_FetchContentID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getEntriesByContentID"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new EntryInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("EntryInfoList.DataPortal_FetchContentID", ex); + throw new DbCslaException("EntryInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class DocIDCriteria + { + public DocIDCriteria(int docID) + { + _DocID = docID; + } + private int _DocID; + public int DocID + { + get { return _DocID; } + set { _DocID = value; } + } + } + private void DataPortal_Fetch(DocIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] EntryInfoList.DataPortal_FetchDocID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getEntriesByDocID"; + cm.Parameters.AddWithValue("@DocID", criteria.DocID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new EntryInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("EntryInfoList.DataPortal_FetchDocID", ex); + throw new DbCslaException("EntryInfoList.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 + EntryInfoListPropertyDescriptor pd = new EntryInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class EntryInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private EntryInfo Item { get { return (EntryInfo) _Item;} } + public EntryInfoListPropertyDescriptor(EntryInfoList collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class EntryInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is EntryInfoList) + { + // Return department and department role separated by comma. + return ((EntryInfoList) value).Items.Count.ToString() + " Entries"; + } + 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 new file mode 100644 index 00000000..ebc8dc2a --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Folder.cs @@ -0,0 +1,1449 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +using Csla.Validation; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static Dictionary _AllByParentID_Name = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Folder tmp in _AllList) + { + _AllByPrimaryKey[tmp.FolderID.ToString()]=tmp; // Primary Key + _AllByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()] = tmp; // Unique Index + remove.Add(tmp); + } + foreach (Folder tmp in remove) + _AllList.Remove(tmp); + } + public static Folder GetExistingByPrimaryKey(int folderID) + { + ConvertListToDictionary(); + string key = folderID.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + return null; + } + public static Folder GetExistingByParentID_Name(int parentID, string name) + { + ConvertListToDictionary(); + string key = parentID.ToString() + "_" + name.ToString(); + if (_AllByParentID_Name.ContainsKey(key)) return _AllByParentID_Name[key]; + 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 != value) + { + _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 _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(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(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; } } + protected Folder() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(FolderID.ToString()); + _AllByParentID_Name.Remove(ParentID.ToString() + "_" + Name.ToString()); + } + 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, 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.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, string config, DateTime dts, string usrID) + { + Folder tmp = Folder.New(myParent, myConnection, name, title, shortName, myFormat, 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, 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.Config = config; + return tmp; + } + public static Folder MakeFolder(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, string config) + { + Folder tmp = Folder.New(myParent, myConnection, name, title, shortName, 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 Folder Get(int folderID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Folder"); + try + { + Folder tmp = GetExistingByPrimaryKey(folderID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(folderID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") tmp = null; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Folder.Get", ex); + } + } + private 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 = GetExistingByParentID_Name(parentID, name); + if (tmp == null) + { + tmp=DataPortal.Fetch(new ParentID_NameCriteria(parentID, name)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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(); + _AllList.Add(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"); + _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("@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, 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("@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("@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, _Config, _DTS, _UsrID); + else + _LastChanged = Folder.Update(cn, ref _FolderID, _MyParent, _MyConnection, _Name, _Title, _ShortName, _MyFormat, _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, 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("@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 + + +//// The following is a sample Extension File. You can use it to create FolderExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class Folder +// { +// partial class FolderExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual int DefaultParentID +// { +// get { return 1; } +// } +// public virtual int DefaultDBID +// { +// get { return 1; } +// } +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUsrID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/FolderAssignment.cs b/PROMS/VEPROMS.CSLA.Library/Generated/FolderAssignment.cs new file mode 100644 index 00000000..b381d1ec --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/FolderAssignment.cs @@ -0,0 +1,696 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +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 +} // Namespace + + +//// The following is a sample Extension File. You can use it to create FolderAssignmentExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class FolderAssignment +// { +// partial class FolderAssignmentExtension : extensionBase +// { +// // 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 AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/FolderAssignments.cs b/PROMS/VEPROMS.CSLA.Library/Generated/FolderAssignments.cs new file mode 100644 index 00000000..be5ff6b4 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/FolderAssignments.cs @@ -0,0 +1,290 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using Csla.Validation; +namespace VEPROMS.CSLA.Library +{ + /// + /// FolderAssignments Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(FolderAssignmentsConverter))] + public partial class FolderAssignments : BusinessListBase, ICustomTypeDescriptor, 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; } + } + // One To Many + public FolderAssignment this[Assignment myAssignment] + { + get + { + foreach (FolderAssignment assignment in this) + if (assignment.AID == myAssignment.AID) + return assignment; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public FolderAssignment GetItem(Assignment myAssignment) + { + foreach (FolderAssignment assignment in this) + if (assignment.AID == myAssignment.AID) + return assignment; + return null; + } + public FolderAssignment Add(Group myGroup, Role myRole) // One to Many + { + FolderAssignment assignment = FolderAssignment.New(myGroup, myRole); + this.Add(assignment); + return assignment; + } + public void Remove(Assignment myAssignment) + { + foreach (FolderAssignment assignment in this) + { + if (assignment.AID == myAssignment.AID) + { + Remove(assignment); + break; + } + } + } + public bool Contains(Assignment myAssignment) + { + foreach (FolderAssignment assignment in this) + if (assignment.AID == myAssignment.AID) + return true; + return false; + } + public bool ContainsDeleted(Assignment myAssignment) + { + foreach (FolderAssignment assignment in DeletedList) + if (assignment.AID == myAssignment.AID) + return true; + return false; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules=null; + foreach(FolderAssignment folderAssignment in this) + if ((hasBrokenRules = folderAssignment.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static FolderAssignments New() + { + return new FolderAssignments(); + } + internal static FolderAssignments Get(SafeDataReader dr) + { + return new FolderAssignments(dr); + } + public static FolderAssignments GetByFolderID(int folderID) + { + try + { + return DataPortal.Fetch(new FolderIDCriteria(folderID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on FolderAssignments.GetByFolderID", ex); + } + } + private FolderAssignments() + { + MarkAsChild(); + } + internal FolderAssignments(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(FolderAssignment.Get(dr)); + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class FolderIDCriteria + { + public FolderIDCriteria(int folderID) + { + _FolderID = folderID; + } + private int _FolderID; + public int FolderID + { + get { return _FolderID; } + set { _FolderID = value; } + } + } + private void DataPortal_Fetch(FolderIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] FolderAssignments.DataPortal_FetchFolderID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAssignmentsByFolderID"; + cm.Parameters.AddWithValue("@FolderID", criteria.FolderID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new FolderAssignment(dr)); + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("FolderAssignments.DataPortal_FetchFolderID", ex); + throw new DbCslaException("FolderAssignments.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(Folder folder) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (FolderAssignment obj in DeletedList) + obj.DeleteSelf(folder);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (FolderAssignment obj in this) + { + if (obj.IsNew) + obj.Insert(folder); + else + obj.Update(folder); + } + } + finally + { + 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 + FolderAssignmentsPropertyDescriptor pd = new FolderAssignmentsPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class FolderAssignmentsPropertyDescriptor : vlnListPropertyDescriptor + { + private FolderAssignment Item { get { return (FolderAssignment) _Item;} } + public FolderAssignmentsPropertyDescriptor(FolderAssignments collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class FolderAssignmentsConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is FolderAssignments) + { + // Return department and department role separated by comma. + return ((FolderAssignments) value).Items.Count.ToString() + " Assignments"; + } + 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 new file mode 100644 index 00000000..d4e73d46 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/FolderDocVersion.cs @@ -0,0 +1,583 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +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 != value) + { + _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 != value) + { + _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 +} // Namespace + + +//// The following is a sample Extension File. You can use it to create FolderDocVersionExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class FolderDocVersion +// { +// partial class FolderDocVersionExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual int DefaultVersionType +// { +// get { return 0; } +// } +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUserID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/FolderDocVersions.cs b/PROMS/VEPROMS.CSLA.Library/Generated/FolderDocVersions.cs new file mode 100644 index 00000000..2e9a58e2 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/FolderDocVersions.cs @@ -0,0 +1,290 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using Csla.Validation; +namespace VEPROMS.CSLA.Library +{ + /// + /// FolderDocVersions Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(FolderDocVersionsConverter))] + public partial class FolderDocVersions : BusinessListBase, ICustomTypeDescriptor, 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; } + } + // One To Many + public FolderDocVersion this[DocVersion myDocVersion] + { + get + { + foreach (FolderDocVersion docVersion in this) + if (docVersion.VersionID == myDocVersion.VersionID) + return docVersion; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public FolderDocVersion GetItem(DocVersion myDocVersion) + { + foreach (FolderDocVersion docVersion in this) + if (docVersion.VersionID == myDocVersion.VersionID) + return docVersion; + return null; + } + public FolderDocVersion Add(string name) // One to Many + { + FolderDocVersion docVersion = FolderDocVersion.New(name); + this.Add(docVersion); + return docVersion; + } + public void Remove(DocVersion myDocVersion) + { + foreach (FolderDocVersion docVersion in this) + { + if (docVersion.VersionID == myDocVersion.VersionID) + { + Remove(docVersion); + break; + } + } + } + public bool Contains(DocVersion myDocVersion) + { + foreach (FolderDocVersion docVersion in this) + if (docVersion.VersionID == myDocVersion.VersionID) + return true; + return false; + } + public bool ContainsDeleted(DocVersion myDocVersion) + { + foreach (FolderDocVersion docVersion in DeletedList) + if (docVersion.VersionID == myDocVersion.VersionID) + return true; + return false; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules=null; + foreach(FolderDocVersion folderDocVersion in this) + if ((hasBrokenRules = folderDocVersion.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static FolderDocVersions New() + { + return new FolderDocVersions(); + } + internal static FolderDocVersions Get(SafeDataReader dr) + { + return new FolderDocVersions(dr); + } + public static FolderDocVersions GetByFolderID(int folderID) + { + try + { + return DataPortal.Fetch(new FolderIDCriteria(folderID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on FolderDocVersions.GetByFolderID", ex); + } + } + private FolderDocVersions() + { + MarkAsChild(); + } + internal FolderDocVersions(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(FolderDocVersion.Get(dr)); + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class FolderIDCriteria + { + public FolderIDCriteria(int folderID) + { + _FolderID = folderID; + } + private int _FolderID; + public int FolderID + { + get { return _FolderID; } + set { _FolderID = value; } + } + } + private void DataPortal_Fetch(FolderIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] FolderDocVersions.DataPortal_FetchFolderID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDocVersionsByFolderID"; + cm.Parameters.AddWithValue("@FolderID", criteria.FolderID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new FolderDocVersion(dr)); + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("FolderDocVersions.DataPortal_FetchFolderID", ex); + throw new DbCslaException("FolderDocVersions.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(Folder folder) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (FolderDocVersion obj in DeletedList) + obj.DeleteSelf(folder);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (FolderDocVersion obj in this) + { + if (obj.IsNew) + obj.Insert(folder); + else + obj.Update(folder); + } + } + finally + { + 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 + FolderDocVersionsPropertyDescriptor pd = new FolderDocVersionsPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class FolderDocVersionsPropertyDescriptor : vlnListPropertyDescriptor + { + private FolderDocVersion Item { get { return (FolderDocVersion) _Item;} } + public FolderDocVersionsPropertyDescriptor(FolderDocVersions collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class FolderDocVersionsConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is FolderDocVersions) + { + // Return department and department role separated by comma. + return ((FolderDocVersions) value).Items.Count.ToString() + " DocVersions"; + } + 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 new file mode 100644 index 00000000..72e9ddfa --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/FolderInfo.cs @@ -0,0 +1,531 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (FolderInfo tmp in _AllList) + { + _AllByPrimaryKey[tmp.FolderID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (FolderInfo tmp in remove) + _AllList.Remove(tmp); + } + internal static void AddList(FolderInfoList lst) + { + foreach (FolderInfo item in lst) _AllList.Add(item); + } + public static FolderInfo GetExistingByPrimaryKey(int folderID) + { + ConvertListToDictionary(); + string key = folderID.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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 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 && _FolderAssignments == null) + _FolderAssignments = AssignmentInfoList.GetByFolderID(_FolderID); + 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 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 && _FolderDocVersions == null) + _FolderDocVersions = DocVersionInfoList.GetByFolderID(_FolderID); + 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 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 && _ChildFolders == null) + _ChildFolders = FolderInfoList.GetChildren(_FolderID); + return _ChildFolders; + } + } + // 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 */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(FolderID.ToString()); + } + public virtual Folder Get() + { + return _Editable = Folder.Get(_FolderID); + } + public static void Refresh(Folder tmp) + { + FolderInfo tmpInfo = GetExistingByPrimaryKey(tmp.FolderID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(Folder tmp) + { + _ParentID = tmp.ParentID; + _DBID = tmp.DBID; + _Name = tmp.Name; + _Title = tmp.Title; + _ShortName = tmp.ShortName; + _FormatID = tmp.FormatID; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _FolderInfoExtension.Refresh(this); + _MyParent = null; + _MyConnection = null; + _MyFormat = null; + OnChange();// raise an event + } + public static void Refresh(ConnectionFolder tmp) + { + FolderInfo tmpInfo = GetExistingByPrimaryKey(tmp.FolderID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(ConnectionFolder tmp) + { + _ParentID = tmp.ParentID; + _Name = tmp.Name; + _Title = tmp.Title; + _ShortName = tmp.ShortName; + _FormatID = tmp.FormatID; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _FolderInfoExtension.Refresh(this); + _MyParent = null; + _MyConnection = null; + _MyFormat = null; + OnChange();// raise an event + } + public static void Refresh(FormatFolder tmp) + { + FolderInfo tmpInfo = GetExistingByPrimaryKey(tmp.FolderID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(FormatFolder tmp) + { + _ParentID = tmp.ParentID; + _DBID = tmp.DBID; + _Name = tmp.Name; + _Title = tmp.Title; + _ShortName = tmp.ShortName; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _FolderInfoExtension.Refresh(this); + _MyParent = null; + _MyConnection = null; + _MyFormat = null; + 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 = GetExistingByPrimaryKey(folderID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(folderID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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"); + _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/Generated/FolderInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/FolderInfoList.cs new file mode 100644 index 00000000..ab1c0c71 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/FolderInfoList.cs @@ -0,0 +1,369 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +namespace VEPROMS.CSLA.Library +{ + /// + /// FolderInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(FolderInfoListConverter))] + public partial class FolderInfoList : 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 (FolderInfo tmp in this) + { + tmp.Changed += new FolderInfoEvent(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)); + } + } + public void Dispose() + { + foreach (FolderInfo tmp in this) + { + tmp.Changed -= new FolderInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static FolderInfoList _FolderInfoList = null; + /// + /// Return a list of all projects. + /// + public static FolderInfoList Get() + { + try + { + if (_FolderInfoList != null) + return _FolderInfoList; + FolderInfoList tmp = DataPortal.Fetch(); + FolderInfo.AddList(tmp); + tmp.AddEvents(); + _FolderInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on FolderInfoList.Get", ex); + } + } + // TODO: Add alternative gets - + //public static FolderInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on FolderInfoList.Get", ex); + // } + //} + public static FolderInfoList GetChildren(int parentID) + { + try + { + FolderInfoList tmp = DataPortal.Fetch(new ParentIDCriteria(parentID)); + FolderInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on FolderInfoList.GetChildren", ex); + } + } + public static FolderInfoList GetByDBID(int dbid) + { + try + { + FolderInfoList tmp = DataPortal.Fetch(new DBIDCriteria(dbid)); + FolderInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on FolderInfoList.GetByDBID", ex); + } + } + public static FolderInfoList GetByFormatID(int? formatID) + { + try + { + FolderInfoList tmp = DataPortal.Fetch(new FormatIDCriteria(formatID)); + FolderInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on FolderInfoList.GetByFormatID", ex); + } + } + private FolderInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] FolderInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getFolders"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new FolderInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("FolderInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("FolderInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class ParentIDCriteria + { + public ParentIDCriteria(int parentID) + { + _ParentID = parentID; + } + private int _ParentID; + public int ParentID + { + get { return _ParentID; } + set { _ParentID = value; } + } + } + private void DataPortal_Fetch(ParentIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] FolderInfoList.DataPortal_FetchParentID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getChildFolders"; + cm.Parameters.AddWithValue("@ParentID", criteria.ParentID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new FolderInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("FolderInfoList.DataPortal_FetchParentID", ex); + throw new DbCslaException("FolderInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class DBIDCriteria + { + public DBIDCriteria(int dbid) + { + _DBID = dbid; + } + private int _DBID; + public int DBID + { + get { return _DBID; } + set { _DBID = value; } + } + } + private void DataPortal_Fetch(DBIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] FolderInfoList.DataPortal_FetchDBID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getFoldersByDBID"; + cm.Parameters.AddWithValue("@DBID", criteria.DBID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new FolderInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("FolderInfoList.DataPortal_FetchDBID", ex); + throw new DbCslaException("FolderInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class FormatIDCriteria + { + public FormatIDCriteria(int? formatID) + { + _FormatID = formatID; + } + private int? _FormatID; + public int? FormatID + { + get { return _FormatID; } + set { _FormatID = value; } + } + } + private void DataPortal_Fetch(FormatIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] FolderInfoList.DataPortal_FetchFormatID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getFoldersByFormatID"; + cm.Parameters.AddWithValue("@FormatID", criteria.FormatID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new FolderInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("FolderInfoList.DataPortal_FetchFormatID", ex); + throw new DbCslaException("FolderInfoList.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 + FolderInfoListPropertyDescriptor pd = new FolderInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class FolderInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private FolderInfo Item { get { return (FolderInfo) _Item;} } + public FolderInfoListPropertyDescriptor(FolderInfoList collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class FolderInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is FolderInfoList) + { + // Return department and department role separated by comma. + return ((FolderInfoList) value).Items.Count.ToString() + " Folders"; + } + 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 new file mode 100644 index 00000000..b05ee2b3 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Format.cs @@ -0,0 +1,1392 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +using Csla.Validation; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static Dictionary _AllByParentID_Name = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Format tmp in _AllList) + { + _AllByPrimaryKey[tmp.FormatID.ToString()]=tmp; // Primary Key + _AllByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()] = tmp; // Unique Index + remove.Add(tmp); + } + foreach (Format tmp in remove) + _AllList.Remove(tmp); + } + public static Format GetExistingByPrimaryKey(int formatID) + { + ConvertListToDictionary(); + string key = formatID.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + return null; + } + public static Format GetExistingByParentID_Name(int parentID, string name) + { + ConvertListToDictionary(); + string key = parentID.ToString() + "_" + name.ToString(); + if (_AllByParentID_Name.ContainsKey(key)) return _AllByParentID_Name[key]; + 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; } } + protected Format() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(FormatID.ToString()); + _AllByParentID_Name.Remove(ParentID.ToString() + "_" + Name.ToString()); + } + 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) + 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 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) + 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 = GetExistingByPrimaryKey(formatID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(formatID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") tmp = null; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Format.Get", ex); + } + } + private 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 = GetExistingByParentID_Name(parentID, name); + if (tmp == null) + { + tmp=DataPortal.Fetch(new ParentID_NameCriteria(parentID, name)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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(); + _AllList.Add(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 + + +//// The following is a sample Extension File. You can use it to create FormatExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class Format +// { +// partial class FormatExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual int DefaultParentID +// { +// get { return 1; } +// } +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUserID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/FormatContent.cs b/PROMS/VEPROMS.CSLA.Library/Generated/FormatContent.cs new file mode 100644 index 00000000..87b8110e --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/FormatContent.cs @@ -0,0 +1,488 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +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 +} // Namespace + + +//// The following is a sample Extension File. You can use it to create FormatContentExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class FormatContent +// { +// partial class FormatContentExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUserID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/FormatContents.cs b/PROMS/VEPROMS.CSLA.Library/Generated/FormatContents.cs new file mode 100644 index 00000000..a631d507 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/FormatContents.cs @@ -0,0 +1,290 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using Csla.Validation; +namespace VEPROMS.CSLA.Library +{ + /// + /// FormatContents Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(FormatContentsConverter))] + public partial class FormatContents : BusinessListBase, ICustomTypeDescriptor, 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; } + } + // One To Many + public FormatContent this[Content myContent] + { + get + { + foreach (FormatContent content in this) + if (content.ContentID == myContent.ContentID) + return content; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public FormatContent GetItem(Content myContent) + { + foreach (FormatContent content in this) + if (content.ContentID == myContent.ContentID) + return content; + return null; + } + public FormatContent Add() // One to Many + { + FormatContent content = FormatContent.New(); + this.Add(content); + return content; + } + public void Remove(Content myContent) + { + foreach (FormatContent content in this) + { + if (content.ContentID == myContent.ContentID) + { + Remove(content); + break; + } + } + } + public bool Contains(Content myContent) + { + foreach (FormatContent content in this) + if (content.ContentID == myContent.ContentID) + return true; + return false; + } + public bool ContainsDeleted(Content myContent) + { + foreach (FormatContent content in DeletedList) + if (content.ContentID == myContent.ContentID) + return true; + return false; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules=null; + foreach(FormatContent formatContent in this) + if ((hasBrokenRules = formatContent.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static FormatContents New() + { + return new FormatContents(); + } + internal static FormatContents Get(SafeDataReader dr) + { + return new FormatContents(dr); + } + public static FormatContents GetByFormatID(int formatID) + { + try + { + return DataPortal.Fetch(new FormatIDCriteria(formatID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on FormatContents.GetByFormatID", ex); + } + } + private FormatContents() + { + MarkAsChild(); + } + internal FormatContents(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(FormatContent.Get(dr)); + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class FormatIDCriteria + { + public FormatIDCriteria(int formatID) + { + _FormatID = formatID; + } + private int _FormatID; + public int FormatID + { + get { return _FormatID; } + set { _FormatID = value; } + } + } + private void DataPortal_Fetch(FormatIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] FormatContents.DataPortal_FetchFormatID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getContentsByFormatID"; + cm.Parameters.AddWithValue("@FormatID", criteria.FormatID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new FormatContent(dr)); + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("FormatContents.DataPortal_FetchFormatID", ex); + throw new DbCslaException("FormatContents.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(Format format) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (FormatContent obj in DeletedList) + obj.DeleteSelf(format);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (FormatContent obj in this) + { + if (obj.IsNew) + obj.Insert(format); + else + obj.Update(format); + } + } + finally + { + 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 + FormatContentsPropertyDescriptor pd = new FormatContentsPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class FormatContentsPropertyDescriptor : vlnListPropertyDescriptor + { + private FormatContent Item { get { return (FormatContent) _Item;} } + public FormatContentsPropertyDescriptor(FormatContents collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class FormatContentsConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is FormatContents) + { + // Return department and department role separated by comma. + return ((FormatContents) value).Items.Count.ToString() + " Contents"; + } + 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 new file mode 100644 index 00000000..36bd9752 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/FormatDocVersion.cs @@ -0,0 +1,700 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +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 != value) + { + _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 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_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 + + +//// The following is a sample Extension File. You can use it to create FormatDocVersionExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class FormatDocVersion +// { +// partial class FormatDocVersionExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual int DefaultVersionType +// { +// get { return 0; } +// } +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUserID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/FormatDocVersions.cs b/PROMS/VEPROMS.CSLA.Library/Generated/FormatDocVersions.cs new file mode 100644 index 00000000..37e6c492 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/FormatDocVersions.cs @@ -0,0 +1,290 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using Csla.Validation; +namespace VEPROMS.CSLA.Library +{ + /// + /// FormatDocVersions Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(FormatDocVersionsConverter))] + public partial class FormatDocVersions : BusinessListBase, ICustomTypeDescriptor, 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; } + } + // One To Many + public FormatDocVersion this[DocVersion myDocVersion] + { + get + { + foreach (FormatDocVersion docVersion in this) + if (docVersion.VersionID == myDocVersion.VersionID) + return docVersion; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public FormatDocVersion GetItem(DocVersion myDocVersion) + { + foreach (FormatDocVersion docVersion in this) + if (docVersion.VersionID == myDocVersion.VersionID) + return docVersion; + return null; + } + public FormatDocVersion Add(Folder myFolder, string name) // One to Many + { + FormatDocVersion docVersion = FormatDocVersion.New(myFolder, name); + this.Add(docVersion); + return docVersion; + } + public void Remove(DocVersion myDocVersion) + { + foreach (FormatDocVersion docVersion in this) + { + if (docVersion.VersionID == myDocVersion.VersionID) + { + Remove(docVersion); + break; + } + } + } + public bool Contains(DocVersion myDocVersion) + { + foreach (FormatDocVersion docVersion in this) + if (docVersion.VersionID == myDocVersion.VersionID) + return true; + return false; + } + public bool ContainsDeleted(DocVersion myDocVersion) + { + foreach (FormatDocVersion docVersion in DeletedList) + if (docVersion.VersionID == myDocVersion.VersionID) + return true; + return false; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules=null; + foreach(FormatDocVersion formatDocVersion in this) + if ((hasBrokenRules = formatDocVersion.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static FormatDocVersions New() + { + return new FormatDocVersions(); + } + internal static FormatDocVersions Get(SafeDataReader dr) + { + return new FormatDocVersions(dr); + } + public static FormatDocVersions GetByFormatID(int formatID) + { + try + { + return DataPortal.Fetch(new FormatIDCriteria(formatID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on FormatDocVersions.GetByFormatID", ex); + } + } + private FormatDocVersions() + { + MarkAsChild(); + } + internal FormatDocVersions(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(FormatDocVersion.Get(dr)); + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class FormatIDCriteria + { + public FormatIDCriteria(int formatID) + { + _FormatID = formatID; + } + private int _FormatID; + public int FormatID + { + get { return _FormatID; } + set { _FormatID = value; } + } + } + private void DataPortal_Fetch(FormatIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] FormatDocVersions.DataPortal_FetchFormatID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDocVersionsByFormatID"; + cm.Parameters.AddWithValue("@FormatID", criteria.FormatID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new FormatDocVersion(dr)); + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("FormatDocVersions.DataPortal_FetchFormatID", ex); + throw new DbCslaException("FormatDocVersions.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(Format format) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (FormatDocVersion obj in DeletedList) + obj.DeleteSelf(format);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (FormatDocVersion obj in this) + { + if (obj.IsNew) + obj.Insert(format); + else + obj.Update(format); + } + } + finally + { + 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 + FormatDocVersionsPropertyDescriptor pd = new FormatDocVersionsPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class FormatDocVersionsPropertyDescriptor : vlnListPropertyDescriptor + { + private FormatDocVersion Item { get { return (FormatDocVersion) _Item;} } + public FormatDocVersionsPropertyDescriptor(FormatDocVersions collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class FormatDocVersionsConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is FormatDocVersions) + { + // Return department and department role separated by comma. + return ((FormatDocVersions) value).Items.Count.ToString() + " DocVersions"; + } + 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 new file mode 100644 index 00000000..11da4aa4 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/FormatFolder.cs @@ -0,0 +1,704 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +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 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(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"); + _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, _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, _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 + + +//// The following is a sample Extension File. You can use it to create FormatFolderExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class FormatFolder +// { +// partial class FormatFolderExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual int DefaultParentID +// { +// get { return 1; } +// } +// public virtual int DefaultDBID +// { +// get { return 1; } +// } +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUsrID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/FormatFolders.cs b/PROMS/VEPROMS.CSLA.Library/Generated/FormatFolders.cs new file mode 100644 index 00000000..e74048d5 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/FormatFolders.cs @@ -0,0 +1,290 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using Csla.Validation; +namespace VEPROMS.CSLA.Library +{ + /// + /// FormatFolders Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(FormatFoldersConverter))] + public partial class FormatFolders : BusinessListBase, ICustomTypeDescriptor, 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; } + } + // One To Many + public FormatFolder this[Folder myFolder] + { + get + { + foreach (FormatFolder folder in this) + if (folder.FolderID == myFolder.FolderID) + return folder; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public FormatFolder GetItem(Folder myFolder) + { + foreach (FormatFolder folder in this) + if (folder.FolderID == myFolder.FolderID) + return folder; + return null; + } + public FormatFolder Add(Folder myParent, string name, string shortName) // One to Many + { + FormatFolder folder = FormatFolder.New(myParent, name, shortName); + this.Add(folder); + return folder; + } + public void Remove(Folder myFolder) + { + foreach (FormatFolder folder in this) + { + if (folder.FolderID == myFolder.FolderID) + { + Remove(folder); + break; + } + } + } + public bool Contains(Folder myFolder) + { + foreach (FormatFolder folder in this) + if (folder.FolderID == myFolder.FolderID) + return true; + return false; + } + public bool ContainsDeleted(Folder myFolder) + { + foreach (FormatFolder folder in DeletedList) + if (folder.FolderID == myFolder.FolderID) + return true; + return false; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules=null; + foreach(FormatFolder formatFolder in this) + if ((hasBrokenRules = formatFolder.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static FormatFolders New() + { + return new FormatFolders(); + } + internal static FormatFolders Get(SafeDataReader dr) + { + return new FormatFolders(dr); + } + public static FormatFolders GetByFormatID(int formatID) + { + try + { + return DataPortal.Fetch(new FormatIDCriteria(formatID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on FormatFolders.GetByFormatID", ex); + } + } + private FormatFolders() + { + MarkAsChild(); + } + internal FormatFolders(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(FormatFolder.Get(dr)); + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class FormatIDCriteria + { + public FormatIDCriteria(int formatID) + { + _FormatID = formatID; + } + private int _FormatID; + public int FormatID + { + get { return _FormatID; } + set { _FormatID = value; } + } + } + private void DataPortal_Fetch(FormatIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] FormatFolders.DataPortal_FetchFormatID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getFoldersByFormatID"; + cm.Parameters.AddWithValue("@FormatID", criteria.FormatID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new FormatFolder(dr)); + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("FormatFolders.DataPortal_FetchFormatID", ex); + throw new DbCslaException("FormatFolders.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(Format format) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (FormatFolder obj in DeletedList) + obj.DeleteSelf(format);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (FormatFolder obj in this) + { + if (obj.IsNew) + obj.Insert(format); + else + obj.Update(format); + } + } + finally + { + 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 + FormatFoldersPropertyDescriptor pd = new FormatFoldersPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class FormatFoldersPropertyDescriptor : vlnListPropertyDescriptor + { + private FormatFolder Item { get { return (FormatFolder) _Item;} } + public FormatFoldersPropertyDescriptor(FormatFolders collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class FormatFoldersConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is FormatFolders) + { + // Return department and department role separated by comma. + return ((FormatFolders) value).Items.Count.ToString() + " Folders"; + } + 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 new file mode 100644 index 00000000..07e4bd0f --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/FormatInfo.cs @@ -0,0 +1,464 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (FormatInfo tmp in _AllList) + { + _AllByPrimaryKey[tmp.FormatID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (FormatInfo tmp in remove) + _AllList.Remove(tmp); + } + internal static void AddList(FormatInfoList lst) + { + foreach (FormatInfo item in lst) _AllList.Add(item); + } + public static FormatInfo GetExistingByPrimaryKey(int formatID) + { + ConvertListToDictionary(); + string key = formatID.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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 && _FormatContents == null) + _FormatContents = ContentInfoList.GetByFormatID(_FormatID); + 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 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 && _FormatDocVersions == null) + _FormatDocVersions = DocVersionInfoList.GetByFormatID(_FormatID); + 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 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 && _FormatFolders == null) + _FormatFolders = FolderInfoList.GetByFormatID(_FormatID); + 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 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 && _ChildFormats == null) + _ChildFormats = FormatInfoList.GetChildren(_FormatID); + return _ChildFormats; + } + } + // 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 FormatInfo() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(FormatID.ToString()); + } + public virtual Format Get() + { + return _Editable = Format.Get(_FormatID); + } + public static void Refresh(Format tmp) + { + FormatInfo tmpInfo = GetExistingByPrimaryKey(tmp.FormatID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(Format tmp) + { + _ParentID = tmp.ParentID; + _Name = tmp.Name; + _Description = tmp.Description; + _Data = tmp.Data; + _GenMac = tmp.GenMac; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _FormatInfoExtension.Refresh(this); + _MyParent = null; + 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 = GetExistingByPrimaryKey(formatID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(formatID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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/Generated/FormatInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/FormatInfoList.cs new file mode 100644 index 00000000..e304b8ea --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/FormatInfoList.cs @@ -0,0 +1,255 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +namespace VEPROMS.CSLA.Library +{ + /// + /// FormatInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(FormatInfoListConverter))] + public partial class FormatInfoList : 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 (FormatInfo tmp in this) + { + tmp.Changed += new FormatInfoEvent(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)); + } + } + public void Dispose() + { + foreach (FormatInfo tmp in this) + { + tmp.Changed -= new FormatInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static FormatInfoList _FormatInfoList = null; + /// + /// Return a list of all projects. + /// + public static FormatInfoList Get() + { + try + { + if (_FormatInfoList != null) + return _FormatInfoList; + FormatInfoList tmp = DataPortal.Fetch(); + FormatInfo.AddList(tmp); + tmp.AddEvents(); + _FormatInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on FormatInfoList.Get", ex); + } + } + // TODO: Add alternative gets - + //public static FormatInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on FormatInfoList.Get", ex); + // } + //} + public static FormatInfoList GetChildren(int parentID) + { + try + { + FormatInfoList tmp = DataPortal.Fetch(new ParentIDCriteria(parentID)); + FormatInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on FormatInfoList.GetChildren", ex); + } + } + private FormatInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] FormatInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getFormats"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new FormatInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("FormatInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("FormatInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class ParentIDCriteria + { + public ParentIDCriteria(int parentID) + { + _ParentID = parentID; + } + private int _ParentID; + public int ParentID + { + get { return _ParentID; } + set { _ParentID = value; } + } + } + private void DataPortal_Fetch(ParentIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] FormatInfoList.DataPortal_FetchParentID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getChildFormats"; + cm.Parameters.AddWithValue("@ParentID", criteria.ParentID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new FormatInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("FormatInfoList.DataPortal_FetchParentID", ex); + throw new DbCslaException("FormatInfoList.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 + FormatInfoListPropertyDescriptor pd = new FormatInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class FormatInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private FormatInfo Item { get { return (FormatInfo) _Item;} } + public FormatInfoListPropertyDescriptor(FormatInfoList collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class FormatInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is FormatInfoList) + { + // Return department and department role separated by comma. + return ((FormatInfoList) value).Items.Count.ToString() + " Formats"; + } + 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 new file mode 100644 index 00000000..9d4e8589 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Group.cs @@ -0,0 +1,1179 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +using Csla.Validation; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static Dictionary _AllByGroupName = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Group tmp in _AllList) + { + _AllByPrimaryKey[tmp.GID.ToString()]=tmp; // Primary Key + _AllByGroupName[tmp.GroupName.ToString()] = tmp; // Unique Index + remove.Add(tmp); + } + foreach (Group tmp in remove) + _AllList.Remove(tmp); + } + public static Group GetExistingByPrimaryKey(int gid) + { + ConvertListToDictionary(); + string key = gid.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + return null; + } + public static Group GetExistingByGroupName(string groupName) + { + ConvertListToDictionary(); + string key = groupName.ToString(); + if (_AllByGroupName.ContainsKey(key)) return _AllByGroupName[key]; + 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; } } + protected Group() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(GID.ToString()); + _AllByGroupName.Remove(GroupName.ToString()); + } + 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 = GetExistingByPrimaryKey(gid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(gid)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") tmp = null; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Group.Get", ex); + } + } + private static Group GetByGroupName(string groupName) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Group"); + try + { + Group tmp = GetExistingByGroupName(groupName); + if (tmp == null) + { + tmp=DataPortal.Fetch(new GroupNameCriteria(groupName)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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(); + _AllList.Add(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 + + +//// The following is a sample Extension File. You can use it to create GroupExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class Group +// { +// partial class GroupExtension : extensionBase +// { +// // 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 AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/GroupAssignment.cs b/PROMS/VEPROMS.CSLA.Library/Generated/GroupAssignment.cs new file mode 100644 index 00000000..a6122546 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/GroupAssignment.cs @@ -0,0 +1,740 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +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 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_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 + + +//// The following is a sample Extension File. You can use it to create GroupAssignmentExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class GroupAssignment +// { +// partial class GroupAssignmentExtension : extensionBase +// { +// // 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 AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/GroupAssignments.cs b/PROMS/VEPROMS.CSLA.Library/Generated/GroupAssignments.cs new file mode 100644 index 00000000..0832fc25 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/GroupAssignments.cs @@ -0,0 +1,290 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using Csla.Validation; +namespace VEPROMS.CSLA.Library +{ + /// + /// GroupAssignments Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(GroupAssignmentsConverter))] + public partial class GroupAssignments : BusinessListBase, ICustomTypeDescriptor, 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; } + } + // One To Many + public GroupAssignment this[Assignment myAssignment] + { + get + { + foreach (GroupAssignment assignment in this) + if (assignment.AID == myAssignment.AID) + return assignment; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public GroupAssignment GetItem(Assignment myAssignment) + { + foreach (GroupAssignment assignment in this) + if (assignment.AID == myAssignment.AID) + return assignment; + return null; + } + public GroupAssignment Add(Role myRole, Folder myFolder) // One to Many + { + GroupAssignment assignment = GroupAssignment.New(myRole, myFolder); + this.Add(assignment); + return assignment; + } + public void Remove(Assignment myAssignment) + { + foreach (GroupAssignment assignment in this) + { + if (assignment.AID == myAssignment.AID) + { + Remove(assignment); + break; + } + } + } + public bool Contains(Assignment myAssignment) + { + foreach (GroupAssignment assignment in this) + if (assignment.AID == myAssignment.AID) + return true; + return false; + } + public bool ContainsDeleted(Assignment myAssignment) + { + foreach (GroupAssignment assignment in DeletedList) + if (assignment.AID == myAssignment.AID) + return true; + return false; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules=null; + foreach(GroupAssignment groupAssignment in this) + if ((hasBrokenRules = groupAssignment.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static GroupAssignments New() + { + return new GroupAssignments(); + } + internal static GroupAssignments Get(SafeDataReader dr) + { + return new GroupAssignments(dr); + } + public static GroupAssignments GetByGID(int gid) + { + try + { + return DataPortal.Fetch(new GIDCriteria(gid)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on GroupAssignments.GetByGID", ex); + } + } + private GroupAssignments() + { + MarkAsChild(); + } + internal GroupAssignments(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(GroupAssignment.Get(dr)); + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class GIDCriteria + { + public GIDCriteria(int gid) + { + _GID = gid; + } + private int _GID; + public int GID + { + get { return _GID; } + set { _GID = value; } + } + } + private void DataPortal_Fetch(GIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] GroupAssignments.DataPortal_FetchGID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAssignmentsByGID"; + cm.Parameters.AddWithValue("@GID", criteria.GID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new GroupAssignment(dr)); + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("GroupAssignments.DataPortal_FetchGID", ex); + throw new DbCslaException("GroupAssignments.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(Group group) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (GroupAssignment obj in DeletedList) + obj.DeleteSelf(group);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (GroupAssignment obj in this) + { + if (obj.IsNew) + obj.Insert(group); + else + obj.Update(group); + } + } + finally + { + 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 + GroupAssignmentsPropertyDescriptor pd = new GroupAssignmentsPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class GroupAssignmentsPropertyDescriptor : vlnListPropertyDescriptor + { + private GroupAssignment Item { get { return (GroupAssignment) _Item;} } + public GroupAssignmentsPropertyDescriptor(GroupAssignments collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class GroupAssignmentsConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is GroupAssignments) + { + // Return department and department role separated by comma. + return ((GroupAssignments) value).Items.Count.ToString() + " Assignments"; + } + 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 new file mode 100644 index 00000000..7473a269 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/GroupInfo.cs @@ -0,0 +1,373 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (GroupInfo tmp in _AllList) + { + _AllByPrimaryKey[tmp.GID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (GroupInfo tmp in remove) + _AllList.Remove(tmp); + } + internal static void AddList(GroupInfoList lst) + { + foreach (GroupInfo item in lst) _AllList.Add(item); + } + public static GroupInfo GetExistingByPrimaryKey(int gid) + { + ConvertListToDictionary(); + string key = gid.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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 && _GroupAssignments == null) + _GroupAssignments = AssignmentInfoList.GetByGID(_GID); + 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 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 && _GroupMemberships == null) + _GroupMemberships = MembershipInfoList.GetByGID(_GID); + return _GroupMemberships; + } + } + // 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 */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(GID.ToString()); + } + public virtual Group Get() + { + return _Editable = Group.Get(_GID); + } + public static void Refresh(Group tmp) + { + GroupInfo tmpInfo = GetExistingByPrimaryKey(tmp.GID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private 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 = GetExistingByPrimaryKey(gid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(gid)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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/Generated/GroupInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/GroupInfoList.cs new file mode 100644 index 00000000..f85f2405 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/GroupInfoList.cs @@ -0,0 +1,198 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +namespace VEPROMS.CSLA.Library +{ + /// + /// GroupInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(GroupInfoListConverter))] + public partial class GroupInfoList : 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 (GroupInfo tmp in this) + { + tmp.Changed += new GroupInfoEvent(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)); + } + } + public void Dispose() + { + foreach (GroupInfo tmp in this) + { + tmp.Changed -= new GroupInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static GroupInfoList _GroupInfoList = null; + /// + /// Return a list of all projects. + /// + public static GroupInfoList Get() + { + try + { + if (_GroupInfoList != null) + return _GroupInfoList; + GroupInfoList tmp = DataPortal.Fetch(); + GroupInfo.AddList(tmp); + tmp.AddEvents(); + _GroupInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on GroupInfoList.Get", ex); + } + } + // TODO: Add alternative gets - + //public static GroupInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on GroupInfoList.Get", ex); + // } + //} + private GroupInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] GroupInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getGroups"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new GroupInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("GroupInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("GroupInfoList.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 + GroupInfoListPropertyDescriptor pd = new GroupInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class GroupInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private GroupInfo Item { get { return (GroupInfo) _Item;} } + public GroupInfoListPropertyDescriptor(GroupInfoList collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class GroupInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is GroupInfoList) + { + // Return department and department role separated by comma. + return ((GroupInfoList) value).Items.Count.ToString() + " Groups"; + } + 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 new file mode 100644 index 00000000..5458b7c2 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/GroupMembership.cs @@ -0,0 +1,720 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +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 +} // Namespace + + +//// The following is a sample Extension File. You can use it to create GroupMembershipExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class GroupMembership +// { +// partial class GroupMembershipExtension : extensionBase +// { +// // 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 AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/GroupMemberships.cs b/PROMS/VEPROMS.CSLA.Library/Generated/GroupMemberships.cs new file mode 100644 index 00000000..c1931e05 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/GroupMemberships.cs @@ -0,0 +1,290 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using Csla.Validation; +namespace VEPROMS.CSLA.Library +{ + /// + /// GroupMemberships Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(GroupMembershipsConverter))] + public partial class GroupMemberships : BusinessListBase, ICustomTypeDescriptor, 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; } + } + // One To Many + public GroupMembership this[Membership myMembership] + { + get + { + foreach (GroupMembership membership in this) + if (membership.UGID == myMembership.UGID) + return membership; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public GroupMembership GetItem(Membership myMembership) + { + foreach (GroupMembership membership in this) + if (membership.UGID == myMembership.UGID) + return membership; + return null; + } + public GroupMembership Add(User myUser) // One to Many + { + GroupMembership membership = GroupMembership.New(myUser); + this.Add(membership); + return membership; + } + public void Remove(Membership myMembership) + { + foreach (GroupMembership membership in this) + { + if (membership.UGID == myMembership.UGID) + { + Remove(membership); + break; + } + } + } + public bool Contains(Membership myMembership) + { + foreach (GroupMembership membership in this) + if (membership.UGID == myMembership.UGID) + return true; + return false; + } + public bool ContainsDeleted(Membership myMembership) + { + foreach (GroupMembership membership in DeletedList) + if (membership.UGID == myMembership.UGID) + return true; + return false; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules=null; + foreach(GroupMembership groupMembership in this) + if ((hasBrokenRules = groupMembership.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static GroupMemberships New() + { + return new GroupMemberships(); + } + internal static GroupMemberships Get(SafeDataReader dr) + { + return new GroupMemberships(dr); + } + public static GroupMemberships GetByGID(int gid) + { + try + { + return DataPortal.Fetch(new GIDCriteria(gid)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on GroupMemberships.GetByGID", ex); + } + } + private GroupMemberships() + { + MarkAsChild(); + } + internal GroupMemberships(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(GroupMembership.Get(dr)); + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class GIDCriteria + { + public GIDCriteria(int gid) + { + _GID = gid; + } + private int _GID; + public int GID + { + get { return _GID; } + set { _GID = value; } + } + } + private void DataPortal_Fetch(GIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] GroupMemberships.DataPortal_FetchGID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getMembershipsByGID"; + cm.Parameters.AddWithValue("@GID", criteria.GID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new GroupMembership(dr)); + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("GroupMemberships.DataPortal_FetchGID", ex); + throw new DbCslaException("GroupMemberships.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(Group group) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (GroupMembership obj in DeletedList) + obj.DeleteSelf(group);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (GroupMembership obj in this) + { + if (obj.IsNew) + obj.Insert(group); + else + obj.Update(group); + } + } + finally + { + 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 + GroupMembershipsPropertyDescriptor pd = new GroupMembershipsPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class GroupMembershipsPropertyDescriptor : vlnListPropertyDescriptor + { + private GroupMembership Item { get { return (GroupMembership) _Item;} } + public GroupMembershipsPropertyDescriptor(GroupMemberships collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class GroupMembershipsConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is GroupMemberships) + { + // Return department and department role separated by comma. + return ((GroupMemberships) value).Items.Count.ToString() + " Memberships"; + } + 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 new file mode 100644 index 00000000..b49b8abd --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Item.cs @@ -0,0 +1,1326 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +using Csla.Validation; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Item tmp in _AllList) + { + _AllByPrimaryKey[tmp.ItemID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (Item tmp in remove) + _AllList.Remove(tmp); + } + public static Item GetExistingByPrimaryKey(int itemID) + { + ConvertListToDictionary(); + string key = itemID.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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 != value) + { + _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; } } + protected Item() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(ItemID.ToString()); + } + 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 = GetExistingByPrimaryKey(itemID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(itemID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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(); + _AllList.Add(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 + + +//// The following is a sample Extension File. You can use it to create ItemExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class Item +// { +// partial class ItemExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUserID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ItemAnnotation.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ItemAnnotation.cs new file mode 100644 index 00000000..a6645e8a --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ItemAnnotation.cs @@ -0,0 +1,569 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +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 +} // Namespace + + +//// The following is a sample Extension File. You can use it to create ItemAnnotationExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class ItemAnnotation +// { +// partial class ItemAnnotationExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUserID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ItemAnnotations.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ItemAnnotations.cs new file mode 100644 index 00000000..6d0549dd --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ItemAnnotations.cs @@ -0,0 +1,290 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using Csla.Validation; +namespace VEPROMS.CSLA.Library +{ + /// + /// ItemAnnotations Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ItemAnnotationsConverter))] + public partial class ItemAnnotations : BusinessListBase, ICustomTypeDescriptor, 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; } + } + // One To Many + public ItemAnnotation this[Annotation myAnnotation] + { + get + { + foreach (ItemAnnotation annotation in this) + if (annotation.AnnotationID == myAnnotation.AnnotationID) + return annotation; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public ItemAnnotation GetItem(Annotation myAnnotation) + { + foreach (ItemAnnotation annotation in this) + if (annotation.AnnotationID == myAnnotation.AnnotationID) + return annotation; + return null; + } + public ItemAnnotation Add(AnnotationType myAnnotationType) // One to Many + { + ItemAnnotation annotation = ItemAnnotation.New(myAnnotationType); + this.Add(annotation); + return annotation; + } + public void Remove(Annotation myAnnotation) + { + foreach (ItemAnnotation annotation in this) + { + if (annotation.AnnotationID == myAnnotation.AnnotationID) + { + Remove(annotation); + break; + } + } + } + public bool Contains(Annotation myAnnotation) + { + foreach (ItemAnnotation annotation in this) + if (annotation.AnnotationID == myAnnotation.AnnotationID) + return true; + return false; + } + public bool ContainsDeleted(Annotation myAnnotation) + { + foreach (ItemAnnotation annotation in DeletedList) + if (annotation.AnnotationID == myAnnotation.AnnotationID) + return true; + return false; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules=null; + foreach(ItemAnnotation itemAnnotation in this) + if ((hasBrokenRules = itemAnnotation.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static ItemAnnotations New() + { + return new ItemAnnotations(); + } + internal static ItemAnnotations Get(SafeDataReader dr) + { + return new ItemAnnotations(dr); + } + public static ItemAnnotations GetByItemID(int itemID) + { + try + { + return DataPortal.Fetch(new ItemIDCriteria(itemID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ItemAnnotations.GetByItemID", ex); + } + } + private ItemAnnotations() + { + MarkAsChild(); + } + internal ItemAnnotations(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(ItemAnnotation.Get(dr)); + 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}] ItemAnnotations.DataPortal_FetchItemID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAnnotationsByItemID"; + cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new ItemAnnotation(dr)); + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("ItemAnnotations.DataPortal_FetchItemID", ex); + throw new DbCslaException("ItemAnnotations.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(Item item) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (ItemAnnotation obj in DeletedList) + obj.DeleteSelf(item);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (ItemAnnotation obj in this) + { + if (obj.IsNew) + obj.Insert(item); + else + obj.Update(item); + } + } + finally + { + 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 + ItemAnnotationsPropertyDescriptor pd = new ItemAnnotationsPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class ItemAnnotationsPropertyDescriptor : vlnListPropertyDescriptor + { + private ItemAnnotation Item { get { return (ItemAnnotation) _Item;} } + public ItemAnnotationsPropertyDescriptor(ItemAnnotations collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class ItemAnnotationsConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ItemAnnotations) + { + // Return department and department role separated by comma. + return ((ItemAnnotations) value).Items.Count.ToString() + " Annotations"; + } + 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 new file mode 100644 index 00000000..231cf34b --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ItemDocVersion.cs @@ -0,0 +1,700 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +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 != value) + { + _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 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_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 + + +//// The following is a sample Extension File. You can use it to create ItemDocVersionExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class ItemDocVersion +// { +// partial class ItemDocVersionExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual int DefaultVersionType +// { +// get { return 0; } +// } +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUserID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ItemDocVersions.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ItemDocVersions.cs new file mode 100644 index 00000000..94d61b7b --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ItemDocVersions.cs @@ -0,0 +1,290 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using Csla.Validation; +namespace VEPROMS.CSLA.Library +{ + /// + /// ItemDocVersions Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ItemDocVersionsConverter))] + public partial class ItemDocVersions : BusinessListBase, ICustomTypeDescriptor, 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; } + } + // One To Many + public ItemDocVersion this[DocVersion myDocVersion] + { + get + { + foreach (ItemDocVersion docVersion in this) + if (docVersion.VersionID == myDocVersion.VersionID) + return docVersion; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public ItemDocVersion GetItem(DocVersion myDocVersion) + { + foreach (ItemDocVersion docVersion in this) + if (docVersion.VersionID == myDocVersion.VersionID) + return docVersion; + return null; + } + public ItemDocVersion Add(Folder myFolder, string name) // One to Many + { + ItemDocVersion docVersion = ItemDocVersion.New(myFolder, name); + this.Add(docVersion); + return docVersion; + } + public void Remove(DocVersion myDocVersion) + { + foreach (ItemDocVersion docVersion in this) + { + if (docVersion.VersionID == myDocVersion.VersionID) + { + Remove(docVersion); + break; + } + } + } + public bool Contains(DocVersion myDocVersion) + { + foreach (ItemDocVersion docVersion in this) + if (docVersion.VersionID == myDocVersion.VersionID) + return true; + return false; + } + public bool ContainsDeleted(DocVersion myDocVersion) + { + foreach (ItemDocVersion docVersion in DeletedList) + if (docVersion.VersionID == myDocVersion.VersionID) + return true; + return false; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules=null; + foreach(ItemDocVersion itemDocVersion in this) + if ((hasBrokenRules = itemDocVersion.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static ItemDocVersions New() + { + return new ItemDocVersions(); + } + internal static ItemDocVersions Get(SafeDataReader dr) + { + return new ItemDocVersions(dr); + } + public static ItemDocVersions GetByItemID(int itemID) + { + try + { + return DataPortal.Fetch(new ItemIDCriteria(itemID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ItemDocVersions.GetByItemID", ex); + } + } + private ItemDocVersions() + { + MarkAsChild(); + } + internal ItemDocVersions(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(ItemDocVersion.Get(dr)); + 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}] ItemDocVersions.DataPortal_FetchItemID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDocVersionsByItemID"; + cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new ItemDocVersion(dr)); + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("ItemDocVersions.DataPortal_FetchItemID", ex); + throw new DbCslaException("ItemDocVersions.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(Item item) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (ItemDocVersion obj in DeletedList) + obj.DeleteSelf(item);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (ItemDocVersion obj in this) + { + if (obj.IsNew) + obj.Insert(item); + else + obj.Update(item); + } + } + finally + { + 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 + ItemDocVersionsPropertyDescriptor pd = new ItemDocVersionsPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class ItemDocVersionsPropertyDescriptor : vlnListPropertyDescriptor + { + private ItemDocVersion Item { get { return (ItemDocVersion) _Item;} } + public ItemDocVersionsPropertyDescriptor(ItemDocVersions collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class ItemDocVersionsConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ItemDocVersions) + { + // Return department and department role separated by comma. + return ((ItemDocVersions) value).Items.Count.ToString() + " DocVersions"; + } + 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 new file mode 100644 index 00000000..5718622b --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ItemInfo.cs @@ -0,0 +1,511 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (ItemInfo tmp in _AllList) + { + _AllByPrimaryKey[tmp.ItemID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (ItemInfo tmp in remove) + _AllList.Remove(tmp); + } + internal static void AddList(ItemInfoList lst) + { + foreach (ItemInfo item in lst) _AllList.Add(item); + } + public static ItemInfo GetExistingByPrimaryKey(int itemID) + { + ConvertListToDictionary(); + string key = itemID.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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 && _ItemAnnotations == null) + _ItemAnnotations = AnnotationInfoList.GetByItemID(_ItemID); + 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 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 && _ItemDocVersions == null) + _ItemDocVersions = DocVersionInfoList.GetByItemID(_ItemID); + 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 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 && _NextItems == null) + _NextItems = ItemInfoList.GetNext(_ItemID); + 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 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 && _ItemParts == null) + _ItemParts = PartInfoList.GetByItemID(_ItemID); + 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 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 && _ItemTransitions_RangeID == null) + _ItemTransitions_RangeID = TransitionInfoList.GetByRangeID(_ItemID); + 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 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 && _ItemTransitions_ToID == null) + _ItemTransitions_ToID = TransitionInfoList.GetByToID(_ItemID); + return _ItemTransitions_ToID; + } + } + // 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 ItemInfo() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(ItemID.ToString()); + } + public virtual Item Get() + { + return _Editable = Item.Get(_ItemID); + } + public static void Refresh(Item tmp) + { + ItemInfo tmpInfo = GetExistingByPrimaryKey(tmp.ItemID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(Item tmp) + { + _PreviousID = tmp.PreviousID; + _ContentID = tmp.ContentID; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _ItemInfoExtension.Refresh(this); + _MyPrevious = null; + _MyContent = null; + OnChange();// raise an event + } + public static void Refresh(ContentItem tmp) + { + ItemInfo tmpInfo = GetExistingByPrimaryKey(tmp.ItemID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(ContentItem tmp) + { + _PreviousID = tmp.PreviousID; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _ItemInfoExtension.Refresh(this); + _MyPrevious = null; + _MyContent = null; + 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 = GetExistingByPrimaryKey(itemID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(itemID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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/Generated/ItemInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ItemInfoList.cs new file mode 100644 index 00000000..a97b353e --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ItemInfoList.cs @@ -0,0 +1,312 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +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); + } + } + void tmp_Changed(object sender) + { + for (int i = 0; i < Count; i++) + { + if (base[i] == sender) + this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i)); + } + } + public void Dispose() + { + foreach (ItemInfo tmp in this) + { + tmp.Changed -= new ItemInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static ItemInfoList _ItemInfoList = null; + /// + /// Return a list of all projects. + /// + 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); + } + } + // TODO: 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"; + 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); + 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); + 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 new file mode 100644 index 00000000..344028a6 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ItemPart.cs @@ -0,0 +1,484 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +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(); + + _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 + + +//// The following is a sample Extension File. You can use it to create ItemPartExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class ItemPart +// { +// partial class ItemPartExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUserID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ItemParts.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ItemParts.cs new file mode 100644 index 00000000..f4623ea9 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ItemParts.cs @@ -0,0 +1,290 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using Csla.Validation; +namespace VEPROMS.CSLA.Library +{ + /// + /// ItemParts Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ItemPartsConverter))] + public partial class ItemParts : BusinessListBase, ICustomTypeDescriptor, 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; } + } + // One To Many + public ItemPart this[Content myContent, int fromType] + { + get + { + foreach (ItemPart part in this) + if (part.ContentID == myContent.ContentID && part.FromType == fromType) + return part; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public ItemPart GetItem(Content myContent, int fromType) + { + foreach (ItemPart part in this) + if (part.ContentID == myContent.ContentID && part.FromType == fromType) + return part; + return null; + } + public ItemPart Add(Content myContent, int fromType) // One to Many + { + ItemPart part = ItemPart.New(myContent, fromType); + this.Add(part); + return part; + } + public void Remove(Content myContent, int fromType) + { + foreach (ItemPart part in this) + { + if (part.ContentID == myContent.ContentID && part.FromType == fromType) + { + Remove(part); + break; + } + } + } + public bool Contains(Content myContent, int fromType) + { + foreach (ItemPart part in this) + if (part.ContentID == myContent.ContentID && part.FromType == fromType) + return true; + return false; + } + public bool ContainsDeleted(Content myContent, int fromType) + { + foreach (ItemPart part in DeletedList) + if (part.ContentID == myContent.ContentID && part.FromType == fromType) + return true; + return false; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules=null; + foreach(ItemPart itemPart in this) + if ((hasBrokenRules = itemPart.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static ItemParts New() + { + return new ItemParts(); + } + internal static ItemParts Get(SafeDataReader dr) + { + return new ItemParts(dr); + } + public static ItemParts GetByItemID(int itemID) + { + try + { + return DataPortal.Fetch(new ItemIDCriteria(itemID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ItemParts.GetByItemID", ex); + } + } + private ItemParts() + { + MarkAsChild(); + } + internal ItemParts(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(ItemPart.Get(dr)); + 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}] ItemParts.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); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new ItemPart(dr)); + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("ItemParts.DataPortal_FetchItemID", ex); + throw new DbCslaException("ItemParts.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(Item item) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (ItemPart obj in DeletedList) + obj.DeleteSelf(item);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (ItemPart obj in this) + { + if (obj.IsNew) + obj.Insert(item); + else + obj.Update(item); + } + } + finally + { + 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 + ItemPartsPropertyDescriptor pd = new ItemPartsPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class ItemPartsPropertyDescriptor : vlnListPropertyDescriptor + { + private ItemPart Item { get { return (ItemPart) _Item;} } + public ItemPartsPropertyDescriptor(ItemParts collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class ItemPartsConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ItemParts) + { + // Return department and department role separated by comma. + return ((ItemParts) value).Items.Count.ToString() + " Parts"; + } + 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 new file mode 100644 index 00000000..993f91e3 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ItemTransition_RangeID.cs @@ -0,0 +1,623 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +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 +} // Namespace + + +//// The following is a sample Extension File. You can use it to create ItemTransition_RangeIDExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class ItemTransition_RangeID +// { +// partial class ItemTransition_RangeIDExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual int DefaultTranType +// { +// get { return 0; } +// } +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUserID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ItemTransition_ToID.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ItemTransition_ToID.cs new file mode 100644 index 00000000..888509dd --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ItemTransition_ToID.cs @@ -0,0 +1,620 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +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 +} // Namespace + + +//// The following is a sample Extension File. You can use it to create ItemTransition_ToIDExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class ItemTransition_ToID +// { +// partial class ItemTransition_ToIDExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual int DefaultTranType +// { +// get { return 0; } +// } +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUserID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ItemTransitions_RangeID.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ItemTransitions_RangeID.cs new file mode 100644 index 00000000..fa1d16a6 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ItemTransitions_RangeID.cs @@ -0,0 +1,290 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using Csla.Validation; +namespace VEPROMS.CSLA.Library +{ + /// + /// ItemTransitions_RangeID Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ItemTransitions_RangeIDConverter))] + public partial class ItemTransitions_RangeID : BusinessListBase, ICustomTypeDescriptor, 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; } + } + // One To Many + public ItemTransition_RangeID this[Transition myTransition] + { + get + { + foreach (ItemTransition_RangeID transition in this) + if (transition.TransitionID == myTransition.TransitionID) + return transition; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public ItemTransition_RangeID GetItem(Transition myTransition) + { + foreach (ItemTransition_RangeID transition in this) + if (transition.TransitionID == myTransition.TransitionID) + return transition; + return null; + } + public ItemTransition_RangeID Add(Content myContent, Item myItemToID) // One to Many + { + ItemTransition_RangeID transition = ItemTransition_RangeID.New(myContent, myItemToID); + this.Add(transition); + return transition; + } + public void Remove(Transition myTransition) + { + foreach (ItemTransition_RangeID transition in this) + { + if (transition.TransitionID == myTransition.TransitionID) + { + Remove(transition); + break; + } + } + } + public bool Contains(Transition myTransition) + { + foreach (ItemTransition_RangeID transition in this) + if (transition.TransitionID == myTransition.TransitionID) + return true; + return false; + } + public bool ContainsDeleted(Transition myTransition) + { + foreach (ItemTransition_RangeID transition in DeletedList) + if (transition.TransitionID == myTransition.TransitionID) + return true; + return false; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules=null; + foreach(ItemTransition_RangeID itemTransitionRangeID in this) + if ((hasBrokenRules = itemTransitionRangeID.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static ItemTransitions_RangeID New() + { + return new ItemTransitions_RangeID(); + } + internal static ItemTransitions_RangeID Get(SafeDataReader dr) + { + return new ItemTransitions_RangeID(dr); + } + public static ItemTransitions_RangeID GetByRangeID(int rangeID) + { + try + { + return DataPortal.Fetch(new RangeIDCriteria(rangeID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ItemTransitions_RangeID.GetByRangeID", ex); + } + } + private ItemTransitions_RangeID() + { + MarkAsChild(); + } + internal ItemTransitions_RangeID(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(ItemTransition_RangeID.Get(dr)); + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class RangeIDCriteria + { + public RangeIDCriteria(int rangeID) + { + _RangeID = rangeID; + } + private int _RangeID; + public int RangeID + { + get { return _RangeID; } + set { _RangeID = value; } + } + } + private void DataPortal_Fetch(RangeIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ItemTransitions_RangeID.DataPortal_FetchRangeID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getTransitionsByRangeID"; + cm.Parameters.AddWithValue("@RangeID", criteria.RangeID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new ItemTransition_RangeID(dr)); + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("ItemTransitions_RangeID.DataPortal_FetchRangeID", ex); + throw new DbCslaException("ItemTransitions_RangeID.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(Item item) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (ItemTransition_RangeID obj in DeletedList) + obj.DeleteSelf(item);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (ItemTransition_RangeID obj in this) + { + if (obj.IsNew) + obj.Insert(item); + else + obj.Update(item); + } + } + finally + { + 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 + ItemTransitions_RangeIDPropertyDescriptor pd = new ItemTransitions_RangeIDPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class ItemTransitions_RangeIDPropertyDescriptor : vlnListPropertyDescriptor + { + private ItemTransition_RangeID Item { get { return (ItemTransition_RangeID) _Item;} } + public ItemTransitions_RangeIDPropertyDescriptor(ItemTransitions_RangeID collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class ItemTransitions_RangeIDConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ItemTransitions_RangeID) + { + // Return department and department role separated by comma. + return ((ItemTransitions_RangeID) value).Items.Count.ToString() + " Transitions_RangeID"; + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ItemTransitions_ToID.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ItemTransitions_ToID.cs new file mode 100644 index 00000000..adfe8453 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ItemTransitions_ToID.cs @@ -0,0 +1,290 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using Csla.Validation; +namespace VEPROMS.CSLA.Library +{ + /// + /// ItemTransitions_ToID Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ItemTransitions_ToIDConverter))] + public partial class ItemTransitions_ToID : BusinessListBase, ICustomTypeDescriptor, 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; } + } + // One To Many + public ItemTransition_ToID this[Transition myTransition] + { + get + { + foreach (ItemTransition_ToID transition in this) + if (transition.TransitionID == myTransition.TransitionID) + return transition; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public ItemTransition_ToID GetItem(Transition myTransition) + { + foreach (ItemTransition_ToID transition in this) + if (transition.TransitionID == myTransition.TransitionID) + return transition; + return null; + } + public ItemTransition_ToID Add(Content myContent, Item myItemRangeID) // One to Many + { + ItemTransition_ToID transition = ItemTransition_ToID.New(myContent, myItemRangeID); + this.Add(transition); + return transition; + } + public void Remove(Transition myTransition) + { + foreach (ItemTransition_ToID transition in this) + { + if (transition.TransitionID == myTransition.TransitionID) + { + Remove(transition); + break; + } + } + } + public bool Contains(Transition myTransition) + { + foreach (ItemTransition_ToID transition in this) + if (transition.TransitionID == myTransition.TransitionID) + return true; + return false; + } + public bool ContainsDeleted(Transition myTransition) + { + foreach (ItemTransition_ToID transition in DeletedList) + if (transition.TransitionID == myTransition.TransitionID) + return true; + return false; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules=null; + foreach(ItemTransition_ToID itemTransitionToID in this) + if ((hasBrokenRules = itemTransitionToID.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static ItemTransitions_ToID New() + { + return new ItemTransitions_ToID(); + } + internal static ItemTransitions_ToID Get(SafeDataReader dr) + { + return new ItemTransitions_ToID(dr); + } + public static ItemTransitions_ToID GetByToID(int toID) + { + try + { + return DataPortal.Fetch(new ToIDCriteria(toID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ItemTransitions_ToID.GetByToID", ex); + } + } + private ItemTransitions_ToID() + { + MarkAsChild(); + } + internal ItemTransitions_ToID(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(ItemTransition_ToID.Get(dr)); + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class ToIDCriteria + { + public ToIDCriteria(int toID) + { + _ToID = toID; + } + private int _ToID; + public int ToID + { + get { return _ToID; } + set { _ToID = value; } + } + } + private void DataPortal_Fetch(ToIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ItemTransitions_ToID.DataPortal_FetchToID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getTransitionsByToID"; + cm.Parameters.AddWithValue("@ToID", criteria.ToID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new ItemTransition_ToID(dr)); + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("ItemTransitions_ToID.DataPortal_FetchToID", ex); + throw new DbCslaException("ItemTransitions_ToID.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(Item item) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (ItemTransition_ToID obj in DeletedList) + obj.DeleteSelf(item);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (ItemTransition_ToID obj in this) + { + if (obj.IsNew) + obj.Insert(item); + else + obj.Update(item); + } + } + finally + { + 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 + ItemTransitions_ToIDPropertyDescriptor pd = new ItemTransitions_ToIDPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class ItemTransitions_ToIDPropertyDescriptor : vlnListPropertyDescriptor + { + private ItemTransition_ToID Item { get { return (ItemTransition_ToID) _Item;} } + public ItemTransitions_ToIDPropertyDescriptor(ItemTransitions_ToID collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class ItemTransitions_ToIDConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ItemTransitions_ToID) + { + // Return department and department role separated by comma. + return ((ItemTransitions_ToID) value).Items.Count.ToString() + " Transitions_ToID"; + } + 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 new file mode 100644 index 00000000..fb06ae06 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Membership.cs @@ -0,0 +1,1148 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +using Csla.Validation; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Membership tmp in _AllList) + { + _AllByPrimaryKey[tmp.UGID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (Membership tmp in remove) + _AllList.Remove(tmp); + } + public static Membership GetExistingByPrimaryKey(int ugid) + { + ConvertListToDictionary(); + string key = ugid.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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; } } + protected Membership() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(UGID.ToString()); + } + 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 = GetExistingByPrimaryKey(ugid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(ugid)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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(); + _AllList.Add(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 + + +//// The following 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 VEPROMS.CSLA.Library +//{ +// public partial class Membership +// { +// partial class MembershipExtension : 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 AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/MembershipInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/MembershipInfo.cs new file mode 100644 index 00000000..fc0454d3 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/MembershipInfo.cs @@ -0,0 +1,407 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (MembershipInfo tmp in _AllList) + { + _AllByPrimaryKey[tmp.UGID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (MembershipInfo tmp in remove) + _AllList.Remove(tmp); + } + internal static void AddList(MembershipInfoList lst) + { + foreach (MembershipInfo item in lst) _AllList.Add(item); + } + public static MembershipInfo GetExistingByPrimaryKey(int ugid) + { + ConvertListToDictionary(); + string key = ugid.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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 MembershipInfo() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(UGID.ToString()); + } + public virtual Membership Get() + { + return _Editable = Membership.Get(_UGID); + } + public static void Refresh(Membership tmp) + { + MembershipInfo tmpInfo = GetExistingByPrimaryKey(tmp.UGID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(Membership tmp) + { + _UID = tmp.UID; + _GID = tmp.GID; + _StartDate = tmp.StartDate; + _EndDate = tmp.EndDate; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _MembershipInfoExtension.Refresh(this); + _MyUser = null; + _MyGroup = null; + OnChange();// raise an event + } + public static void Refresh(GroupMembership tmp) + { + MembershipInfo tmpInfo = GetExistingByPrimaryKey(tmp.UGID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(GroupMembership tmp) + { + _UID = tmp.UID; + _StartDate = tmp.StartDate; + _EndDate = tmp.EndDate; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _MembershipInfoExtension.Refresh(this); + _MyUser = null; + _MyGroup = null; + OnChange();// raise an event + } + public static void Refresh(UserMembership tmp) + { + MembershipInfo tmpInfo = GetExistingByPrimaryKey(tmp.UGID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(UserMembership tmp) + { + _GID = tmp.GID; + _StartDate = tmp.StartDate; + _EndDate = tmp.EndDate; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _MembershipInfoExtension.Refresh(this); + _MyUser = null; + _MyGroup = null; + 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 = GetExistingByPrimaryKey(ugid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(ugid)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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/Generated/MembershipInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/MembershipInfoList.cs new file mode 100644 index 00000000..ec17ea2e --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/MembershipInfoList.cs @@ -0,0 +1,312 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +namespace VEPROMS.CSLA.Library +{ + /// + /// MembershipInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(MembershipInfoListConverter))] + public partial class MembershipInfoList : 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 (MembershipInfo tmp in this) + { + tmp.Changed += new MembershipInfoEvent(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)); + } + } + public void Dispose() + { + foreach (MembershipInfo tmp in this) + { + tmp.Changed -= new MembershipInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static MembershipInfoList _MembershipInfoList = null; + /// + /// Return a list of all projects. + /// + public static MembershipInfoList Get() + { + try + { + if (_MembershipInfoList != null) + return _MembershipInfoList; + MembershipInfoList tmp = DataPortal.Fetch(); + MembershipInfo.AddList(tmp); + tmp.AddEvents(); + _MembershipInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on MembershipInfoList.Get", ex); + } + } + // TODO: Add alternative gets - + //public static MembershipInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on MembershipInfoList.Get", ex); + // } + //} + public static MembershipInfoList GetByGID(int gid) + { + try + { + MembershipInfoList tmp = DataPortal.Fetch(new GIDCriteria(gid)); + MembershipInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on MembershipInfoList.GetByGID", ex); + } + } + public static MembershipInfoList GetByUID(int uid) + { + try + { + MembershipInfoList tmp = DataPortal.Fetch(new UIDCriteria(uid)); + MembershipInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on MembershipInfoList.GetByUID", ex); + } + } + private MembershipInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] MembershipInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getMemberships"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new MembershipInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("MembershipInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("MembershipInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class GIDCriteria + { + public GIDCriteria(int gid) + { + _GID = gid; + } + private int _GID; + public int GID + { + get { return _GID; } + set { _GID = value; } + } + } + private void DataPortal_Fetch(GIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] MembershipInfoList.DataPortal_FetchGID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getMembershipsByGID"; + cm.Parameters.AddWithValue("@GID", criteria.GID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new MembershipInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("MembershipInfoList.DataPortal_FetchGID", ex); + throw new DbCslaException("MembershipInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class UIDCriteria + { + public UIDCriteria(int uid) + { + _UID = uid; + } + private int _UID; + public int UID + { + get { return _UID; } + set { _UID = value; } + } + } + private void DataPortal_Fetch(UIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] MembershipInfoList.DataPortal_FetchUID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getMembershipsByUID"; + cm.Parameters.AddWithValue("@UID", criteria.UID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new MembershipInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("MembershipInfoList.DataPortal_FetchUID", ex); + throw new DbCslaException("MembershipInfoList.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 + MembershipInfoListPropertyDescriptor pd = new MembershipInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class MembershipInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private MembershipInfo Item { get { return (MembershipInfo) _Item;} } + public MembershipInfoListPropertyDescriptor(MembershipInfoList collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class MembershipInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is MembershipInfoList) + { + // Return department and department role separated by comma. + return ((MembershipInfoList) value).Items.Count.ToString() + " Memberships"; + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/NextItems.cs b/PROMS/VEPROMS.CSLA.Library/Generated/NextItems.cs new file mode 100644 index 00000000..d52591d6 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/NextItems.cs @@ -0,0 +1,290 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using Csla.Validation; +namespace VEPROMS.CSLA.Library +{ + /// + /// NextItems Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(NextItemsConverter))] + public partial class NextItems : BusinessListBase, ICustomTypeDescriptor, 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; } + } + // One To Many + public new Item this[int itemID] + { + get + { + foreach (Item item in this) + if (item.ItemID == itemID) + return item; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public Item GetItem(int itemID) + { + foreach (Item item in this) + if (item.ItemID == itemID) + return item; + return null; + } + public Item Add(Content myContent) // One to Many + { + Item item = Item.New(myContent); + this.Add(item); + return item; + } + public void Remove(int itemID) + { + foreach (Item item in this) + { + if (item.ItemID == itemID) + { + Remove(item); + break; + } + } + } + public bool Contains(int itemID) + { + foreach (Item item in this) + if (item.ItemID == itemID) + return true; + return false; + } + public bool ContainsDeleted(int itemID) + { + foreach (Item item in DeletedList) + if (item.ItemID == itemID) + return true; + return false; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules=null; + foreach(Item item in this) + if ((hasBrokenRules = item.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static NextItems New() + { + return new NextItems(); + } + internal static NextItems Get(SafeDataReader dr, Item parent) + { + return new NextItems(dr, parent); + } + public static NextItems GetByPreviousID(int previousID) + { + try + { + return DataPortal.Fetch(new PreviousIDCriteria(previousID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on NextItems.GetByPreviousID", ex); + } + } + private NextItems() + { + MarkAsChild(); + } + internal NextItems(SafeDataReader dr, Item parent) + { + MarkAsChild(); + Fetch(dr, parent); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr, Item parent) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(Item.Get(dr, parent)); + 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}] NextItems.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); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new Item(dr, criteria.PreviousID)); + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("NextItems.DataPortal_FetchPreviousID", ex); + throw new DbCslaException("NextItems.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(Item item) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (Item obj in DeletedList) + obj.DeleteSelf(item);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (Item obj in this) + { + if (obj.IsNew) + obj.SQLInsert(); + else + obj.SQLUpdate(); + } + } + finally + { + 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 + NextItemsPropertyDescriptor pd = new NextItemsPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class NextItemsPropertyDescriptor : vlnListPropertyDescriptor + { + private Item Item { get { return (Item) _Item;} } + public NextItemsPropertyDescriptor(NextItems collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class NextItemsConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is NextItems) + { + // Return department and department role separated by comma. + return ((NextItems) value).Items.Count.ToString() + " Items"; + } + 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 new file mode 100644 index 00000000..7ed0ad75 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Part.cs @@ -0,0 +1,957 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +using Csla.Validation; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Part tmp in _AllList) + { + _AllByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (Part tmp in remove) + _AllList.Remove(tmp); + } + public static Part GetExistingByPrimaryKey(int contentID, int fromType) + { + ConvertListToDictionary(); + string key = contentID.ToString() + "_" + fromType.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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; } } + protected Part() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(ContentID.ToString() + "_" + FromType.ToString()); + } + 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 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 = GetExistingByPrimaryKey(contentID, fromType); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(contentID, fromType)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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(); + _AllList.Add(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 +} // Namespace + + +//// The following is a sample Extension File. You can use it to create PartExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class Part +// { +// partial class PartExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUserID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/PartInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/PartInfo.cs new file mode 100644 index 00000000..246a114e --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/PartInfo.cs @@ -0,0 +1,370 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (PartInfo tmp in _AllList) + { + _AllByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (PartInfo tmp in remove) + _AllList.Remove(tmp); + } + internal static void AddList(PartInfoList lst) + { + foreach (PartInfo item in lst) _AllList.Add(item); + } + public static PartInfo GetExistingByPrimaryKey(int contentID, int fromType) + { + ConvertListToDictionary(); + string key = contentID.ToString() + "_" + fromType.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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 PartInfo() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(ContentID.ToString() + "_" + FromType.ToString()); + } + public virtual Part Get() + { + return _Editable = Part.Get(_ContentID, _FromType); + } + public static void Refresh(Part tmp) + { + PartInfo tmpInfo = GetExistingByPrimaryKey(tmp.ContentID, tmp.FromType); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(Part tmp) + { + _ItemID = tmp.ItemID; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _PartInfoExtension.Refresh(this); + _MyContent = null; + _MyItem = null; + OnChange();// raise an event + } + public static void Refresh(Content myContent, ContentPart tmp) + { + PartInfo tmpInfo = GetExistingByPrimaryKey(myContent.ContentID, tmp.FromType); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(ContentPart tmp) + { + _ItemID = tmp.ItemID; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _PartInfoExtension.Refresh(this); + _MyContent = null; + _MyItem = null; + OnChange();// raise an event + } + public static void Refresh(ItemPart tmp) + { + PartInfo tmpInfo = GetExistingByPrimaryKey(tmp.ContentID, tmp.FromType); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(ItemPart tmp) + { + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _PartInfoExtension.Refresh(this); + _MyContent = null; + _MyItem = null; + 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 = GetExistingByPrimaryKey(contentID, fromType); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(contentID, fromType)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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/Generated/PartInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/PartInfoList.cs new file mode 100644 index 00000000..9932a0a2 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/PartInfoList.cs @@ -0,0 +1,312 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +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)); + } + } + public void Dispose() + { + 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 projects. + /// + 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); + } + } + // TODO: 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"; + 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); + 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); + 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/Permission.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Permission.cs new file mode 100644 index 00000000..e2a8a91a --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Permission.cs @@ -0,0 +1,1231 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +using Csla.Validation; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Permission tmp in _AllList) + { + _AllByPrimaryKey[tmp.PID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (Permission tmp in remove) + _AllList.Remove(tmp); + } + public static Permission GetExistingByPrimaryKey(int pid) + { + ConvertListToDictionary(); + string key = pid.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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; } } + protected Permission() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(PID.ToString()); + } + 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 = GetExistingByPrimaryKey(pid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(pid)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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(); + _AllList.Add(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 + + +//// The following 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 VEPROMS.CSLA.Library +//{ +// public partial class Permission +// { +// partial class PermissionExtension : 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 AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/PermissionInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/PermissionInfo.cs new file mode 100644 index 00000000..9c41537c --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/PermissionInfo.cs @@ -0,0 +1,425 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (PermissionInfo tmp in _AllList) + { + _AllByPrimaryKey[tmp.PID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (PermissionInfo tmp in remove) + _AllList.Remove(tmp); + } + internal static void AddList(PermissionInfoList lst) + { + foreach (PermissionInfo item in lst) _AllList.Add(item); + } + public static PermissionInfo GetExistingByPrimaryKey(int pid) + { + ConvertListToDictionary(); + string key = pid.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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 PermissionInfo() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(PID.ToString()); + } + public virtual Permission Get() + { + return _Editable = Permission.Get(_PID); + } + public static void Refresh(Permission tmp) + { + PermissionInfo tmpInfo = GetExistingByPrimaryKey(tmp.PID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(Permission tmp) + { + _RID = tmp.RID; + _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); + _MyRole = null; + OnChange();// raise an event + } + public static void Refresh(RolePermission tmp) + { + PermissionInfo tmpInfo = GetExistingByPrimaryKey(tmp.PID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private 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); + _MyRole = null; + 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 = GetExistingByPrimaryKey(pid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(pid)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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/Generated/PermissionInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/PermissionInfoList.cs new file mode 100644 index 00000000..ae109ee2 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/PermissionInfoList.cs @@ -0,0 +1,255 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +namespace VEPROMS.CSLA.Library +{ + /// + /// PermissionInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(PermissionInfoListConverter))] + public partial class PermissionInfoList : 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 (PermissionInfo tmp in this) + { + tmp.Changed += new PermissionInfoEvent(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)); + } + } + public void Dispose() + { + foreach (PermissionInfo tmp in this) + { + tmp.Changed -= new PermissionInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static PermissionInfoList _PermissionInfoList = null; + /// + /// Return a list of all projects. + /// + public static PermissionInfoList Get() + { + try + { + if (_PermissionInfoList != null) + return _PermissionInfoList; + PermissionInfoList tmp = DataPortal.Fetch(); + PermissionInfo.AddList(tmp); + tmp.AddEvents(); + _PermissionInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on PermissionInfoList.Get", ex); + } + } + // TODO: Add alternative gets - + //public static PermissionInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on PermissionInfoList.Get", ex); + // } + //} + public static PermissionInfoList GetByRID(int rid) + { + try + { + PermissionInfoList tmp = DataPortal.Fetch(new RIDCriteria(rid)); + PermissionInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on PermissionInfoList.GetByRID", ex); + } + } + private PermissionInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] PermissionInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getPermissions"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new PermissionInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("PermissionInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("PermissionInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class RIDCriteria + { + public RIDCriteria(int rid) + { + _RID = rid; + } + private int _RID; + public int RID + { + get { return _RID; } + set { _RID = value; } + } + } + private void DataPortal_Fetch(RIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] PermissionInfoList.DataPortal_FetchRID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getPermissionsByRID"; + cm.Parameters.AddWithValue("@RID", criteria.RID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new PermissionInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("PermissionInfoList.DataPortal_FetchRID", ex); + throw new DbCslaException("PermissionInfoList.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 + PermissionInfoListPropertyDescriptor pd = new PermissionInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class PermissionInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private PermissionInfo Item { get { return (PermissionInfo) _Item;} } + public PermissionInfoListPropertyDescriptor(PermissionInfoList collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class PermissionInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is PermissionInfoList) + { + // Return department and department role separated by comma. + return ((PermissionInfoList) value).Items.Count.ToString() + " Permissions"; + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/PropertyDescriptor.cs b/PROMS/VEPROMS.CSLA.Library/Generated/PropertyDescriptor.cs new file mode 100644 index 00000000..5e891bc8 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/PropertyDescriptor.cs @@ -0,0 +1,197 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using Csla.Validation; +namespace VEPROMS.CSLA.Library +{ + /// + /// PropertyDescriptor Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + public partial class vlnListPropertyDescriptor : PropertyDescriptor + { + protected object _Item = null; + public vlnListPropertyDescriptor(System.Collections.IList collection, int index) + : base("#" + index.ToString(), null) + { _Item = collection[index]; } + public override bool CanResetValue(object component) + { return true; } + public override Type ComponentType + { get { return _Item.GetType(); } } + public override object GetValue(object component) + { return _Item; } + public override bool IsReadOnly + { get { return false; } } + public override Type PropertyType + { get { return _Item.GetType(); } } + public override void ResetValue(object component) + { ;} + public override bool ShouldSerializeValue(object component) + { return true; } + public override void SetValue(object component, object value) + { /*_Item = value*/;} + //public override AttributeCollection Attributes + //{ get { return new AttributeCollection(null); } } + public override string DisplayName + { get { return _Item.ToString(); } } + public override string Description + { get { return _Item.ToString(); } } + public override string Name + { get { return _Item.ToString(); } } + } // Class + public interface IVEHasBrokenRules + { + IVEHasBrokenRules HasBrokenRules { get; } + BrokenRulesCollection BrokenRules { get; } + } +} // Namespace +// The following are samples of ToString overrides +// public partial class Annotation +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class AnnotationInfo +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class AnnotationType +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class AnnotationTypeAnnotation +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class AnnotationTypeInfo +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class Assignment +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class AssignmentInfo +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class Connection +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class ConnectionFolder +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class ConnectionInfo +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class Content +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class ContentDetail +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class ContentItem +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class ContentPart +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class ContentRoUsage +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class ContentTransition +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class ContentInfo +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class Detail +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class DetailInfo +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class Document +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class DocumentEntry +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class DocumentInfo +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class DocVersion +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class DocVersionInfo +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class Entry +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class EntryInfo +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class Folder +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class FolderAssignment +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class FolderDocVersion +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class FolderInfo +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class Format +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class FormatContent +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class FormatDocVersion +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class FormatFolder +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class FormatInfo +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class Group +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class GroupAssignment +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class GroupMembership +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class GroupInfo +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class Item +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class ItemAnnotation +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class ItemDocVersion +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class ItemPart +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class ItemTransition_RangeID +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class ItemTransition_ToID +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class ItemInfo +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class Membership +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class MembershipInfo +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class Part +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class PartInfo +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class Permission +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class PermissionInfo +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class Role +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class RoleAssignment +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class RolePermission +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class RoleInfo +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class RoUsage +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class RoUsageInfo +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class Transition +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class TransitionInfo +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class User +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class UserMembership +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class UserInfo +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class ZContent +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class ZContentInfo +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class ZTransition +// { public override string ToString() { return string.Format("{0}", _Name); } } +// public partial class ZTransitionInfo +// { public override string ToString() { return string.Format("{0}", _Name); } } \ No newline at end of file diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RoUsage.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RoUsage.cs new file mode 100644 index 00000000..b8b079b5 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RoUsage.cs @@ -0,0 +1,1020 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +using Csla.Validation; +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); + } + } + #endregion + #region Collection + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (RoUsage tmp in _AllList) + { + _AllByPrimaryKey[tmp.ROUsageID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (RoUsage tmp in remove) + _AllList.Remove(tmp); + } + public static RoUsage GetExistingByPrimaryKey(int rOUsageID) + { + ConvertListToDictionary(); + string key = rOUsageID.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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 + 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 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; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules=false; + } + } + } + public 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.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; + } + // Sample data comparison validation rule + //private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e) + //{ + // if (_started > _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.AllowWrite(ContentID, ""); + //AuthorizationRules.AllowWrite(ROID, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _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; } } + protected RoUsage() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(ROUsageID.ToString()); + } + 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) + { + RoUsage tmp = RoUsage.New(); + tmp.ROID = roid; + return tmp; + } + public static RoUsage New(Content myContent, string roid, string config, DateTime dts, string userID) + { + RoUsage tmp = RoUsage.New(); + tmp.MyContent = myContent; + tmp.ROID = roid; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static RoUsage MakeRoUsage(Content myContent, string roid, string config, DateTime dts, string userID) + { + RoUsage tmp = RoUsage.New(myContent, roid, 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 RoUsage New(Content myContent, string roid, string config) + { + RoUsage tmp = RoUsage.New(); + tmp.MyContent = myContent; + tmp.ROID = roid; + tmp.Config = config; + return tmp; + } + public static RoUsage MakeRoUsage(Content myContent, string roid, string config) + { + RoUsage tmp = RoUsage.New(myContent, roid, 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 RoUsage Get(int rOUsageID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a RoUsage"); + try + { + RoUsage tmp = GetExistingByPrimaryKey(rOUsageID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(rOUsageID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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(); + _AllList.Add(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); + 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(); + 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); + // 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) + { + 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); + // 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(); + 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); + // 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); + else + _LastChanged = RoUsage.Update(cn, ref _ROUsageID, _MyContent, _ROID, _Config, _DTS, _UserID, ref _LastChanged); + 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) + { + 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); + // 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 + + +//// The following is a sample Extension File. You can use it to create RoUsageExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class RoUsage +// { +// partial class RoUsageExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual int DefaultContentID +// { +// get { return 0; } +// } +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUserID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RoUsageInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RoUsageInfo.cs new file mode 100644 index 00000000..1247b730 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RoUsageInfo.cs @@ -0,0 +1,348 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (RoUsageInfo tmp in _AllList) + { + _AllByPrimaryKey[tmp.ROUsageID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (RoUsageInfo tmp in remove) + _AllList.Remove(tmp); + } + internal static void AddList(RoUsageInfoList lst) + { + foreach (RoUsageInfo item in lst) _AllList.Add(item); + } + public static RoUsageInfo GetExistingByPrimaryKey(int rOUsageID) + { + ConvertListToDictionary(); + string key = rOUsageID.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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; + } + } + // 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 RoUsageInfo() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(ROUsageID.ToString()); + } + public virtual RoUsage Get() + { + return _Editable = RoUsage.Get(_ROUsageID); + } + public static void Refresh(RoUsage tmp) + { + RoUsageInfo tmpInfo = GetExistingByPrimaryKey(tmp.ROUsageID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(RoUsage tmp) + { + _ContentID = tmp.ContentID; + _ROID = tmp.ROID; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _RoUsageInfoExtension.Refresh(this); + _MyContent = null; + OnChange();// raise an event + } + public static void Refresh(ContentRoUsage tmp) + { + RoUsageInfo tmpInfo = GetExistingByPrimaryKey(tmp.ROUsageID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(ContentRoUsage tmp) + { + _ROID = tmp.ROID; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _RoUsageInfoExtension.Refresh(this); + _MyContent = null; + 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 = GetExistingByPrimaryKey(rOUsageID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(rOUsageID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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"); + } + 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/Generated/RoUsageInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RoUsageInfoList.cs new file mode 100644 index 00000000..be879125 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RoUsageInfoList.cs @@ -0,0 +1,255 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +namespace VEPROMS.CSLA.Library +{ + /// + /// RoUsageInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RoUsageInfoListConverter))] + public partial class RoUsageInfoList : 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 (RoUsageInfo tmp in this) + { + tmp.Changed += new RoUsageInfoEvent(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)); + } + } + public void Dispose() + { + foreach (RoUsageInfo tmp in this) + { + tmp.Changed -= new RoUsageInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static RoUsageInfoList _RoUsageInfoList = null; + /// + /// Return a list of all projects. + /// + public static RoUsageInfoList Get() + { + try + { + if (_RoUsageInfoList != null) + return _RoUsageInfoList; + RoUsageInfoList tmp = DataPortal.Fetch(); + RoUsageInfo.AddList(tmp); + tmp.AddEvents(); + _RoUsageInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on RoUsageInfoList.Get", ex); + } + } + // TODO: Add alternative gets - + //public static RoUsageInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on RoUsageInfoList.Get", ex); + // } + //} + public static RoUsageInfoList GetByContentID(int contentID) + { + try + { + RoUsageInfoList tmp = DataPortal.Fetch(new ContentIDCriteria(contentID)); + RoUsageInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on RoUsageInfoList.GetByContentID", ex); + } + } + private RoUsageInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] RoUsageInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getRoUsages"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new RoUsageInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("RoUsageInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("RoUsageInfoList.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}] RoUsageInfoList.DataPortal_FetchContentID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getRoUsagesByContentID"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new RoUsageInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("RoUsageInfoList.DataPortal_FetchContentID", ex); + throw new DbCslaException("RoUsageInfoList.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 + RoUsageInfoListPropertyDescriptor pd = new RoUsageInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class RoUsageInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private RoUsageInfo Item { get { return (RoUsageInfo) _Item;} } + public RoUsageInfoListPropertyDescriptor(RoUsageInfoList collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class RoUsageInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RoUsageInfoList) + { + // Return department and department role separated by comma. + return ((RoUsageInfoList) value).Items.Count.ToString() + " RoUsages"; + } + 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 new file mode 100644 index 00000000..56e737ff --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Role.cs @@ -0,0 +1,1130 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +using Csla.Validation; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static Dictionary _AllByName = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Role tmp in _AllList) + { + _AllByPrimaryKey[tmp.RID.ToString()]=tmp; // Primary Key + _AllByName[tmp.Name.ToString()] = tmp; // Unique Index + remove.Add(tmp); + } + foreach (Role tmp in remove) + _AllList.Remove(tmp); + } + public static Role GetExistingByPrimaryKey(int rid) + { + ConvertListToDictionary(); + string key = rid.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + return null; + } + public static Role GetExistingByName(string name) + { + ConvertListToDictionary(); + string key = name.ToString(); + if (_AllByName.ContainsKey(key)) return _AllByName[key]; + 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; } } + protected Role() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(RID.ToString()); + _AllByName.Remove(Name.ToString()); + } + 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 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 = GetExistingByPrimaryKey(rid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(rid)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") tmp = null; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Role.Get", ex); + } + } + private static Role GetByName(string name) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Role"); + try + { + Role tmp = GetExistingByName(name); + if (tmp == null) + { + tmp=DataPortal.Fetch(new NameCriteria(name)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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(); + _AllList.Add(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 + + +//// The following 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 VEPROMS.CSLA.Library +//{ +// public partial class Role +// { +// partial class RoleExtension : 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 AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RoleAssignment.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RoleAssignment.cs new file mode 100644 index 00000000..b3642ab3 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RoleAssignment.cs @@ -0,0 +1,751 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +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 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_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 + + +//// The following 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 VEPROMS.CSLA.Library +//{ +// public partial class RoleAssignment +// { +// partial class RoleAssignmentExtension : 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 AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RoleAssignments.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RoleAssignments.cs new file mode 100644 index 00000000..894632ec --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RoleAssignments.cs @@ -0,0 +1,290 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using Csla.Validation; +namespace VEPROMS.CSLA.Library +{ + /// + /// RoleAssignments Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RoleAssignmentsConverter))] + public partial class RoleAssignments : BusinessListBase, ICustomTypeDescriptor, 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; } + } + // One To Many + public RoleAssignment this[Assignment myAssignment] + { + get + { + foreach (RoleAssignment assignment in this) + if (assignment.AID == myAssignment.AID) + return assignment; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public RoleAssignment GetItem(Assignment myAssignment) + { + foreach (RoleAssignment assignment in this) + if (assignment.AID == myAssignment.AID) + return assignment; + return null; + } + public RoleAssignment Add(Group myGroup, Folder myFolder) // One to Many + { + RoleAssignment assignment = RoleAssignment.New(myGroup, myFolder); + this.Add(assignment); + return assignment; + } + public void Remove(Assignment myAssignment) + { + foreach (RoleAssignment assignment in this) + { + if (assignment.AID == myAssignment.AID) + { + Remove(assignment); + break; + } + } + } + public bool Contains(Assignment myAssignment) + { + foreach (RoleAssignment assignment in this) + if (assignment.AID == myAssignment.AID) + return true; + return false; + } + public bool ContainsDeleted(Assignment myAssignment) + { + foreach (RoleAssignment assignment in DeletedList) + if (assignment.AID == myAssignment.AID) + return true; + return false; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules=null; + foreach(RoleAssignment roleAssignment in this) + if ((hasBrokenRules = roleAssignment.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static RoleAssignments New() + { + return new RoleAssignments(); + } + internal static RoleAssignments Get(SafeDataReader dr) + { + return new RoleAssignments(dr); + } + public static RoleAssignments GetByRID(int rid) + { + try + { + return DataPortal.Fetch(new RIDCriteria(rid)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on RoleAssignments.GetByRID", ex); + } + } + private RoleAssignments() + { + MarkAsChild(); + } + internal RoleAssignments(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(RoleAssignment.Get(dr)); + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class RIDCriteria + { + public RIDCriteria(int rid) + { + _RID = rid; + } + private int _RID; + public int RID + { + get { return _RID; } + set { _RID = value; } + } + } + private void DataPortal_Fetch(RIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] RoleAssignments.DataPortal_FetchRID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAssignmentsByRID"; + cm.Parameters.AddWithValue("@RID", criteria.RID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new RoleAssignment(dr)); + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("RoleAssignments.DataPortal_FetchRID", ex); + throw new DbCslaException("RoleAssignments.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(Role role) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (RoleAssignment obj in DeletedList) + obj.DeleteSelf(role);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (RoleAssignment obj in this) + { + if (obj.IsNew) + obj.Insert(role); + else + obj.Update(role); + } + } + finally + { + 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 + RoleAssignmentsPropertyDescriptor pd = new RoleAssignmentsPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class RoleAssignmentsPropertyDescriptor : vlnListPropertyDescriptor + { + private RoleAssignment Item { get { return (RoleAssignment) _Item;} } + public RoleAssignmentsPropertyDescriptor(RoleAssignments collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class RoleAssignmentsConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RoleAssignments) + { + // Return department and department role separated by comma. + return ((RoleAssignments) value).Items.Count.ToString() + " Assignments"; + } + 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 new file mode 100644 index 00000000..a5b40f59 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RoleInfo.cs @@ -0,0 +1,361 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (RoleInfo tmp in _AllList) + { + _AllByPrimaryKey[tmp.RID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (RoleInfo tmp in remove) + _AllList.Remove(tmp); + } + internal static void AddList(RoleInfoList lst) + { + foreach (RoleInfo item in lst) _AllList.Add(item); + } + public static RoleInfo GetExistingByPrimaryKey(int rid) + { + ConvertListToDictionary(); + string key = rid.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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 && _RoleAssignments == null) + _RoleAssignments = AssignmentInfoList.GetByRID(_RID); + 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 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 && _RolePermissions == null) + _RolePermissions = PermissionInfoList.GetByRID(_RID); + return _RolePermissions; + } + } + // 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 */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(RID.ToString()); + } + public virtual Role Get() + { + return _Editable = Role.Get(_RID); + } + public static void Refresh(Role tmp) + { + RoleInfo tmpInfo = GetExistingByPrimaryKey(tmp.RID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private 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 = GetExistingByPrimaryKey(rid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(rid)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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/Generated/RoleInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RoleInfoList.cs new file mode 100644 index 00000000..ba180935 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RoleInfoList.cs @@ -0,0 +1,198 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +namespace VEPROMS.CSLA.Library +{ + /// + /// RoleInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RoleInfoListConverter))] + public partial class RoleInfoList : 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 (RoleInfo tmp in this) + { + tmp.Changed += new RoleInfoEvent(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)); + } + } + public void Dispose() + { + foreach (RoleInfo tmp in this) + { + tmp.Changed -= new RoleInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static RoleInfoList _RoleInfoList = null; + /// + /// Return a list of all projects. + /// + public static RoleInfoList Get() + { + try + { + if (_RoleInfoList != null) + return _RoleInfoList; + RoleInfoList tmp = DataPortal.Fetch(); + RoleInfo.AddList(tmp); + tmp.AddEvents(); + _RoleInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on RoleInfoList.Get", ex); + } + } + // TODO: Add alternative gets - + //public static RoleInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on RoleInfoList.Get", ex); + // } + //} + private RoleInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] RoleInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getRoles"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new RoleInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("RoleInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("RoleInfoList.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 + RoleInfoListPropertyDescriptor pd = new RoleInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class RoleInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private RoleInfo Item { get { return (RoleInfo) _Item;} } + public RoleInfoListPropertyDescriptor(RoleInfoList collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class RoleInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RoleInfoList) + { + // Return department and department role separated by comma. + return ((RoleInfoList) value).Items.Count.ToString() + " Roles"; + } + 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 new file mode 100644 index 00000000..1af92685 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RolePermission.cs @@ -0,0 +1,639 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +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 +} // Namespace + + +//// The following 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 VEPROMS.CSLA.Library +//{ +// public partial class RolePermission +// { +// partial class RolePermissionExtension : 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 AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RolePermissions.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RolePermissions.cs new file mode 100644 index 00000000..28ba8b39 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RolePermissions.cs @@ -0,0 +1,290 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using Csla.Validation; +namespace VEPROMS.CSLA.Library +{ + /// + /// RolePermissions Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RolePermissionsConverter))] + public partial class RolePermissions : BusinessListBase, ICustomTypeDescriptor, 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; } + } + // One To Many + public RolePermission this[Permission myPermission] + { + get + { + foreach (RolePermission permission in this) + if (permission.PID == myPermission.PID) + return permission; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public RolePermission GetItem(Permission myPermission) + { + foreach (RolePermission permission in this) + if (permission.PID == myPermission.PID) + return permission; + return null; + } + public RolePermission Add(int permLevel, int versionType, int permValue) // One to Many + { + RolePermission permission = RolePermission.New(permLevel, versionType, permValue); + this.Add(permission); + return permission; + } + public void Remove(Permission myPermission) + { + foreach (RolePermission permission in this) + { + if (permission.PID == myPermission.PID) + { + Remove(permission); + break; + } + } + } + public bool Contains(Permission myPermission) + { + foreach (RolePermission permission in this) + if (permission.PID == myPermission.PID) + return true; + return false; + } + public bool ContainsDeleted(Permission myPermission) + { + foreach (RolePermission permission in DeletedList) + if (permission.PID == myPermission.PID) + return true; + return false; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules=null; + foreach(RolePermission rolePermission in this) + if ((hasBrokenRules = rolePermission.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static RolePermissions New() + { + return new RolePermissions(); + } + internal static RolePermissions Get(SafeDataReader dr) + { + return new RolePermissions(dr); + } + public static RolePermissions GetByRID(int rid) + { + try + { + return DataPortal.Fetch(new RIDCriteria(rid)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on RolePermissions.GetByRID", ex); + } + } + private RolePermissions() + { + MarkAsChild(); + } + internal RolePermissions(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(RolePermission.Get(dr)); + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class RIDCriteria + { + public RIDCriteria(int rid) + { + _RID = rid; + } + private int _RID; + public int RID + { + get { return _RID; } + set { _RID = value; } + } + } + private void DataPortal_Fetch(RIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] RolePermissions.DataPortal_FetchRID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getPermissionsByRID"; + cm.Parameters.AddWithValue("@RID", criteria.RID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new RolePermission(dr)); + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("RolePermissions.DataPortal_FetchRID", ex); + throw new DbCslaException("RolePermissions.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(Role role) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (RolePermission obj in DeletedList) + obj.DeleteSelf(role);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (RolePermission obj in this) + { + if (obj.IsNew) + obj.Insert(role); + else + obj.Update(role); + } + } + finally + { + 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 + RolePermissionsPropertyDescriptor pd = new RolePermissionsPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class RolePermissionsPropertyDescriptor : vlnListPropertyDescriptor + { + private RolePermission Item { get { return (RolePermission) _Item;} } + public RolePermissionsPropertyDescriptor(RolePermissions collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class RolePermissionsConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RolePermissions) + { + // Return department and department role separated by comma. + return ((RolePermissions) value).Items.Count.ToString() + " Permissions"; + } + 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 new file mode 100644 index 00000000..96a35932 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Transition.cs @@ -0,0 +1,1177 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +using Csla.Validation; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Transition tmp in _AllList) + { + _AllByPrimaryKey[tmp.TransitionID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (Transition tmp in remove) + _AllList.Remove(tmp); + } + public static Transition GetExistingByPrimaryKey(int transitionID) + { + ConvertListToDictionary(); + string key = transitionID.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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; } } + protected Transition() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(TransitionID.ToString()); + } + 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) + 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 = GetExistingByPrimaryKey(transitionID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(transitionID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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(); + _AllList.Add(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 + + +//// The following is a sample Extension File. You can use it to create TransitionExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class Transition +// { +// partial class TransitionExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public virtual int DefaultTranType +// { +// get { return 0; } +// } +// public virtual DateTime DefaultDTS +// { +// get { return DateTime.Now; } +// } +// public virtual string DefaultUserID +// { +// get { return Environment.UserName.ToUpper(); } +// } +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/TransitionInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/TransitionInfo.cs new file mode 100644 index 00000000..6e2d252d --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/TransitionInfo.cs @@ -0,0 +1,476 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (TransitionInfo tmp in _AllList) + { + _AllByPrimaryKey[tmp.TransitionID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (TransitionInfo tmp in remove) + _AllList.Remove(tmp); + } + internal static void AddList(TransitionInfoList lst) + { + foreach (TransitionInfo item in lst) _AllList.Add(item); + } + public static TransitionInfo GetExistingByPrimaryKey(int transitionID) + { + ConvertListToDictionary(); + string key = transitionID.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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); + 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 TransitionInfo() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(TransitionID.ToString()); + } + public virtual Transition Get() + { + return _Editable = Transition.Get(_TransitionID); + } + public static void Refresh(Transition tmp) + { + TransitionInfo tmpInfo = GetExistingByPrimaryKey(tmp.TransitionID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(Transition tmp) + { + _FromID = tmp.FromID; + _ToID = tmp.ToID; + _RangeID = tmp.RangeID; + _TranType = tmp.TranType; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _TransitionInfoExtension.Refresh(this); + _MyContent = null; + _MyItemToID = null; + _MyItemRangeID = null; + _MyZTransition = null; + OnChange();// raise an event + } + public static void Refresh(ContentTransition tmp) + { + TransitionInfo tmpInfo = GetExistingByPrimaryKey(tmp.TransitionID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(ContentTransition tmp) + { + _ToID = tmp.ToID; + _RangeID = tmp.RangeID; + _TranType = tmp.TranType; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _TransitionInfoExtension.Refresh(this); + _MyContent = null; + _MyItemToID = null; + _MyItemRangeID = null; + _MyZTransition = null; + OnChange();// raise an event + } + public static void Refresh(ItemTransition_RangeID tmp) + { + TransitionInfo tmpInfo = GetExistingByPrimaryKey(tmp.TransitionID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(ItemTransition_RangeID tmp) + { + _FromID = tmp.FromID; + _ToID = tmp.ToID; + _TranType = tmp.TranType; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _TransitionInfoExtension.Refresh(this); + _MyContent = null; + _MyItemToID = null; + _MyItemRangeID = null; + _MyZTransition = null; + OnChange();// raise an event + } + public static void Refresh(ItemTransition_ToID tmp) + { + TransitionInfo tmpInfo = GetExistingByPrimaryKey(tmp.TransitionID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(ItemTransition_ToID tmp) + { + _FromID = tmp.FromID; + _RangeID = tmp.RangeID; + _TranType = tmp.TranType; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _TransitionInfoExtension.Refresh(this); + _MyContent = null; + _MyItemToID = null; + _MyItemRangeID = null; + _MyZTransition = null; + 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 = GetExistingByPrimaryKey(transitionID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(transitionID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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/Generated/TransitionInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/TransitionInfoList.cs new file mode 100644 index 00000000..c1e61270 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/TransitionInfoList.cs @@ -0,0 +1,369 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +namespace VEPROMS.CSLA.Library +{ + /// + /// TransitionInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(TransitionInfoListConverter))] + public partial class TransitionInfoList : 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 (TransitionInfo tmp in this) + { + tmp.Changed += new TransitionInfoEvent(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)); + } + } + public void Dispose() + { + foreach (TransitionInfo tmp in this) + { + tmp.Changed -= new TransitionInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static TransitionInfoList _TransitionInfoList = null; + /// + /// Return a list of all projects. + /// + public static TransitionInfoList Get() + { + try + { + if (_TransitionInfoList != null) + return _TransitionInfoList; + TransitionInfoList tmp = DataPortal.Fetch(); + TransitionInfo.AddList(tmp); + tmp.AddEvents(); + _TransitionInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on TransitionInfoList.Get", ex); + } + } + // TODO: Add alternative gets - + //public static TransitionInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on TransitionInfoList.Get", ex); + // } + //} + public static TransitionInfoList GetByFromID(int fromID) + { + try + { + TransitionInfoList tmp = DataPortal.Fetch(new FromIDCriteria(fromID)); + TransitionInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on TransitionInfoList.GetByFromID", ex); + } + } + public static TransitionInfoList GetByRangeID(int rangeID) + { + try + { + TransitionInfoList tmp = DataPortal.Fetch(new RangeIDCriteria(rangeID)); + TransitionInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on TransitionInfoList.GetByRangeID", ex); + } + } + public static TransitionInfoList GetByToID(int toID) + { + try + { + TransitionInfoList tmp = DataPortal.Fetch(new ToIDCriteria(toID)); + TransitionInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on TransitionInfoList.GetByToID", ex); + } + } + private TransitionInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] TransitionInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getTransitions"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new TransitionInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("TransitionInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("TransitionInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class FromIDCriteria + { + public FromIDCriteria(int fromID) + { + _FromID = fromID; + } + private int _FromID; + public int FromID + { + get { return _FromID; } + set { _FromID = value; } + } + } + private void DataPortal_Fetch(FromIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] TransitionInfoList.DataPortal_FetchFromID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getTransitionsByFromID"; + cm.Parameters.AddWithValue("@FromID", criteria.FromID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new TransitionInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("TransitionInfoList.DataPortal_FetchFromID", ex); + throw new DbCslaException("TransitionInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class RangeIDCriteria + { + public RangeIDCriteria(int rangeID) + { + _RangeID = rangeID; + } + private int _RangeID; + public int RangeID + { + get { return _RangeID; } + set { _RangeID = value; } + } + } + private void DataPortal_Fetch(RangeIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] TransitionInfoList.DataPortal_FetchRangeID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getTransitionsByRangeID"; + cm.Parameters.AddWithValue("@RangeID", criteria.RangeID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new TransitionInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("TransitionInfoList.DataPortal_FetchRangeID", ex); + throw new DbCslaException("TransitionInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class ToIDCriteria + { + public ToIDCriteria(int toID) + { + _ToID = toID; + } + private int _ToID; + public int ToID + { + get { return _ToID; } + set { _ToID = value; } + } + } + private void DataPortal_Fetch(ToIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] TransitionInfoList.DataPortal_FetchToID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getTransitionsByToID"; + cm.Parameters.AddWithValue("@ToID", criteria.ToID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new TransitionInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("TransitionInfoList.DataPortal_FetchToID", ex); + throw new DbCslaException("TransitionInfoList.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 + TransitionInfoListPropertyDescriptor pd = new TransitionInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class TransitionInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private TransitionInfo Item { get { return (TransitionInfo) _Item;} } + public TransitionInfoListPropertyDescriptor(TransitionInfoList collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class TransitionInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is TransitionInfoList) + { + // Return department and department role separated by comma. + return ((TransitionInfoList) value).Items.Count.ToString() + " Transitions"; + } + 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 new file mode 100644 index 00000000..62be73c1 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/User.cs @@ -0,0 +1,1320 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +using Csla.Validation; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (User tmp in _AllList) + { + _AllByPrimaryKey[tmp.UID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (User tmp in remove) + _AllList.Remove(tmp); + } + public static User GetExistingByPrimaryKey(int uid) + { + ConvertListToDictionary(); + string key = uid.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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; } } + protected User() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(UID.ToString()); + } + 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 = GetExistingByPrimaryKey(uid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(uid)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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(); + _AllList.Add(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 + + +//// The following 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 VEPROMS.CSLA.Library +//{ +// public partial class User +// { +// partial class UserExtension : 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 AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/UserInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/UserInfo.cs new file mode 100644 index 00000000..602b62d1 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/UserInfo.cs @@ -0,0 +1,442 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (UserInfo tmp in _AllList) + { + _AllByPrimaryKey[tmp.UID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (UserInfo tmp in remove) + _AllList.Remove(tmp); + } + internal static void AddList(UserInfoList lst) + { + foreach (UserInfo item in lst) _AllList.Add(item); + } + public static UserInfo GetExistingByPrimaryKey(int uid) + { + ConvertListToDictionary(); + string key = uid.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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 && _UserMemberships == null) + _UserMemberships = MembershipInfoList.GetByUID(_UID); + return _UserMemberships; + } + } + // 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 */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(UID.ToString()); + } + public virtual User Get() + { + return _Editable = User.Get(_UID); + } + public static void Refresh(User tmp) + { + UserInfo tmpInfo = GetExistingByPrimaryKey(tmp.UID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private 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 = GetExistingByPrimaryKey(uid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(uid)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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/Generated/UserInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/UserInfoList.cs new file mode 100644 index 00000000..a72e7450 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/UserInfoList.cs @@ -0,0 +1,198 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +namespace VEPROMS.CSLA.Library +{ + /// + /// UserInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(UserInfoListConverter))] + public partial class UserInfoList : 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 (UserInfo tmp in this) + { + tmp.Changed += new UserInfoEvent(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)); + } + } + public void Dispose() + { + foreach (UserInfo tmp in this) + { + tmp.Changed -= new UserInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static UserInfoList _UserInfoList = null; + /// + /// Return a list of all projects. + /// + public static UserInfoList Get() + { + try + { + if (_UserInfoList != null) + return _UserInfoList; + UserInfoList tmp = DataPortal.Fetch(); + UserInfo.AddList(tmp); + tmp.AddEvents(); + _UserInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on UserInfoList.Get", ex); + } + } + // TODO: Add alternative gets - + //public static UserInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on UserInfoList.Get", ex); + // } + //} + private UserInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] UserInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getUsers"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new UserInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("UserInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("UserInfoList.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 + UserInfoListPropertyDescriptor pd = new UserInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class UserInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private UserInfo Item { get { return (UserInfo) _Item;} } + public UserInfoListPropertyDescriptor(UserInfoList collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class UserInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is UserInfoList) + { + // Return department and department role separated by comma. + return ((UserInfoList) value).Items.Count.ToString() + " Users"; + } + 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 new file mode 100644 index 00000000..cdc905ef --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/UserMembership.cs @@ -0,0 +1,632 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +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 +} // Namespace + + +//// The following 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 VEPROMS.CSLA.Library +//{ +// public partial class UserMembership +// { +// partial class UserMembershipExtension : 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 AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/UserMemberships.cs b/PROMS/VEPROMS.CSLA.Library/Generated/UserMemberships.cs new file mode 100644 index 00000000..1c6cd007 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/UserMemberships.cs @@ -0,0 +1,290 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using Csla.Validation; +namespace VEPROMS.CSLA.Library +{ + /// + /// UserMemberships Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(UserMembershipsConverter))] + public partial class UserMemberships : BusinessListBase, ICustomTypeDescriptor, 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; } + } + // One To Many + public UserMembership this[Membership myMembership] + { + get + { + foreach (UserMembership membership in this) + if (membership.UGID == myMembership.UGID) + return membership; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public UserMembership GetItem(Membership myMembership) + { + foreach (UserMembership membership in this) + if (membership.UGID == myMembership.UGID) + return membership; + return null; + } + public UserMembership Add(Group myGroup) // One to Many + { + UserMembership membership = UserMembership.New(myGroup); + this.Add(membership); + return membership; + } + public void Remove(Membership myMembership) + { + foreach (UserMembership membership in this) + { + if (membership.UGID == myMembership.UGID) + { + Remove(membership); + break; + } + } + } + public bool Contains(Membership myMembership) + { + foreach (UserMembership membership in this) + if (membership.UGID == myMembership.UGID) + return true; + return false; + } + public bool ContainsDeleted(Membership myMembership) + { + foreach (UserMembership membership in DeletedList) + if (membership.UGID == myMembership.UGID) + return true; + return false; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules=null; + foreach(UserMembership userMembership in this) + if ((hasBrokenRules = userMembership.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static UserMemberships New() + { + return new UserMemberships(); + } + internal static UserMemberships Get(SafeDataReader dr) + { + return new UserMemberships(dr); + } + public static UserMemberships GetByUID(int uid) + { + try + { + return DataPortal.Fetch(new UIDCriteria(uid)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on UserMemberships.GetByUID", ex); + } + } + private UserMemberships() + { + MarkAsChild(); + } + internal UserMemberships(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(UserMembership.Get(dr)); + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class UIDCriteria + { + public UIDCriteria(int uid) + { + _UID = uid; + } + private int _UID; + public int UID + { + get { return _UID; } + set { _UID = value; } + } + } + private void DataPortal_Fetch(UIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] UserMemberships.DataPortal_FetchUID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getMembershipsByUID"; + cm.Parameters.AddWithValue("@UID", criteria.UID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new UserMembership(dr)); + } + } + } + } + catch (Exception ex) + { + if(_MyLog.IsErrorEnabled)_MyLog.Error("UserMemberships.DataPortal_FetchUID", ex); + throw new DbCslaException("UserMemberships.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(User user) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (UserMembership obj in DeletedList) + obj.DeleteSelf(user);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (UserMembership obj in this) + { + if (obj.IsNew) + obj.Insert(user); + else + obj.Update(user); + } + } + finally + { + 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 + UserMembershipsPropertyDescriptor pd = new UserMembershipsPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class UserMembershipsPropertyDescriptor : vlnListPropertyDescriptor + { + private UserMembership Item { get { return (UserMembership) _Item;} } + public UserMembershipsPropertyDescriptor(UserMemberships collection, int index):base(collection, index){;} + } + #endregion + #region Converter + internal class UserMembershipsConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is UserMemberships) + { + // Return department and department role separated by comma. + return ((UserMemberships) value).Items.Count.ToString() + " Memberships"; + } + 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 new file mode 100644 index 00000000..21d53593 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ZContent.cs @@ -0,0 +1,823 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +using Csla.Validation; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (ZContent tmp in _AllList) + { + _AllByPrimaryKey[tmp.ContentID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (ZContent tmp in remove) + _AllList.Remove(tmp); + } + public static ZContent GetExistingByPrimaryKey(int contentID) + { + ConvertListToDictionary(); + string key = contentID.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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; } } + protected ZContent() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(ContentID.ToString()); + } + 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 = GetExistingByPrimaryKey(contentID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(contentID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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(); + _AllList.Add(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 + + // 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 + + +//// The following is a sample Extension File. You can use it to create ZContentExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class ZContent +// { +// partial class ZContentExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ZContentInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ZContentInfo.cs new file mode 100644 index 00000000..98935f09 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ZContentInfo.cs @@ -0,0 +1,284 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (ZContentInfo tmp in _AllList) + { + _AllByPrimaryKey[tmp.ContentID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (ZContentInfo tmp in remove) + _AllList.Remove(tmp); + } + public static ZContentInfo GetExistingByPrimaryKey(int contentID) + { + ConvertListToDictionary(); + string key = contentID.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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 ZContentInfo() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(ContentID.ToString()); + } + public virtual ZContent Get() + { + return _Editable = ZContent.Get(_ContentID); + } + public static void Refresh(ZContent tmp) + { + ZContentInfo tmpInfo = GetExistingByPrimaryKey(tmp.ContentID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(ZContent tmp) + { + _OldStepSequence = tmp.OldStepSequence; + _ZContentInfoExtension.Refresh(this); + _MyContent = null; + 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 = GetExistingByPrimaryKey(contentID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(contentID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp._ContentID = contentID; + } + 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/Generated/ZTransition.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ZTransition.cs new file mode 100644 index 00000000..365ea14a --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ZTransition.cs @@ -0,0 +1,823 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +using Csla.Validation; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (ZTransition tmp in _AllList) + { + _AllByPrimaryKey[tmp.TransitionID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (ZTransition tmp in remove) + _AllList.Remove(tmp); + } + public static ZTransition GetExistingByPrimaryKey(int transitionID) + { + ConvertListToDictionary(); + string key = transitionID.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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; } } + protected ZTransition() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(TransitionID.ToString()); + } + 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 = GetExistingByPrimaryKey(transitionID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(transitionID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") 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(); + _AllList.Add(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 + + // 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 + + +//// The following is a sample Extension File. You can use it to create ZTransitionExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class ZTransition +// { +// partial class ZTransitionExtension : extensionBase +// { +// // TODO: Override automatic defaults +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// public new void AddValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddRule( +// Csla.Validation.CommonRules.StringMaxLength, +// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); +// } +// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) +// { +// rules.AddInstanceRule(/* Instance Validation Rule */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ZTransitionInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ZTransitionInfo.cs new file mode 100644 index 00000000..8258ebb5 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ZTransitionInfo.cs @@ -0,0 +1,284 @@ +// ======================================================================== +// Copyright 2007 - Volian Enterprises, Inc. All rights reserved. +// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE +// ------------------------------------------------------------------------ +// $Workfile: $ $Revision: $ +// $Author: $ $Date: $ +// +// $History: $ +// ======================================================================== + +using System; +using System.Data; +using System.Data.SqlClient; +using Csla; +using Csla.Data; +using System.Configuration; +using System.IO; +using System.ComponentModel; +using System.Collections.Generic; +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 + protected static List _AllList = new List(); + private static Dictionary _AllByPrimaryKey = new Dictionary(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (ZTransitionInfo tmp in _AllList) + { + _AllByPrimaryKey[tmp.TransitionID.ToString()]=tmp; // Primary Key + remove.Add(tmp); + } + foreach (ZTransitionInfo tmp in remove) + _AllList.Remove(tmp); + } + public static ZTransitionInfo GetExistingByPrimaryKey(int transitionID) + { + ConvertListToDictionary(); + string key = transitionID.ToString(); + if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key]; + 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 ZTransitionInfo() + {/* require use of factory methods */ + _AllList.Add(this); + } + public void Dispose() + { + _AllList.Remove(this); + _AllByPrimaryKey.Remove(TransitionID.ToString()); + } + public virtual ZTransition Get() + { + return _Editable = ZTransition.Get(_TransitionID); + } + public static void Refresh(ZTransition tmp) + { + ZTransitionInfo tmpInfo = GetExistingByPrimaryKey(tmp.TransitionID); + if (tmpInfo == null) return; + tmpInfo.RefreshFields(tmp); + } + private void RefreshFields(ZTransition tmp) + { + _Oldto = tmp.Oldto; + _ZTransitionInfoExtension.Refresh(this); + _MyTransition = null; + 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 = GetExistingByPrimaryKey(transitionID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(transitionID)); + _AllList.Add(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp._TransitionID = transitionID; + } + 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.CSLA.Library/Properties/AssemblyInfo.cs b/PROMS/VEPROMS.CSLA.Library/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..9479c207 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("VEPROMS.CSLA.Library")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Volian Enterprises, Inc.")] +[assembly: AssemblyProduct("VEPROMS.CSLA.Library")] +[assembly: AssemblyCopyright("Copyright © Volian Enterprises, Inc. 2007")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("2355ff14-e26f-48d9-b221-5d064a4bc12c")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/PROMS/VEPROMS.CSLA.Library/VEObjects/VEDrillDown.cs b/PROMS/VEPROMS.CSLA.Library/VEObjects/VEDrillDown.cs new file mode 100644 index 00000000..dfd37520 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/VEObjects/VEDrillDown.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.ComponentModel; + +namespace VEPROMS.CSLA.Library +{ + [TypeConverter(typeof(ExpandableObjectConverter))] + public interface IVEDrillDownReadOnly + { + System.Collections.IList GetChildren(); // Returns a list of Business Objects + //bool ChildrenAreLoaded { get; }; // Have the Business Objects been Loaded + bool HasChildren { get; } // Identifies if Children are available + IVEDrillDownReadOnly ActiveParent { get; } + FormatInfo ActiveFormat { get; } + FormatInfo LocalFormat { get; } + string ToString(); + DynamicTypeDescriptor MyConfig { get; } + //IVEDrillDown Get(); + //bool HasStandardSteps(); + // Ideas Authorization + //bool CanLock(); + //bool CanUnlock(); + //bool CanOpen(); + //bool CanEdit(); + //bool CanAdmin(); + // Ideas Security + //bool Lock(string msg); + //bool Unlock(); + } + [TypeConverter(typeof(ExpandableObjectConverter))] + public interface IVEDrillDown : IVEHasBrokenRules + { + System.Collections.IList GetChildren(); // Returns a list of Business Objects + //bool GetChildrenLoaded(); // Have the Business Objects been Loaded + bool HasChildren { get; } // Identifies if Children are available + IVEDrillDown ActiveParent { get; } + Format ActiveFormat { get; } + Format LocalFormat { get; } + //bool HasStandardSteps(); + // Ideas Authorization + //bool CanLock(); + //bool CanUnlock(); + //bool CanOpen(); + //bool CanEdit(); + //bool CanAdmin(); + // Ideas Security + //bool Lock(string msg); + //bool Unlock(); + } + +} diff --git a/PROMS/VEPROMS.CSLA.Library/VEObjects/VETreeNode.cs b/PROMS/VEPROMS.CSLA.Library/VEObjects/VETreeNode.cs new file mode 100644 index 00000000..fb4dd268 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/VEObjects/VETreeNode.cs @@ -0,0 +1,485 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows.Forms; +using Csla; +using System.Collections; +using System.ComponentModel; +using System.Drawing; +using System.Reflection; + +namespace VEPROMS.CSLA.Library +{ + public delegate void VETreeNodeEvent(object sender, VETreeNodeEventArgs args); + public class VETreeNodeEventArgs : EventArgs + { + public VETreeNodeEventArgs() { ; } + public VETreeNodeEventArgs(string info) + { + _Info = info; + } + public VETreeNodeEventArgs(int value) + { + _Value = value; + } + public VETreeNodeEventArgs(string info, int value) + { + _Info = info; + _Value = value; + } + private int _Value; + + public int Value + { + get { return _Value; } + set { _Value = value; } + } + private string _Info; + + public string Info + { + get { return _Info; } + set { _Info = value; } + } + + } + public class VETreeNode : TreeNode + { + #region Events + public event VETreeNodeEvent LoadingChildrenSQL; + public event VETreeNodeEvent LoadingChildernMax; + public event VETreeNodeEvent LoadingChildernValue; + public event VETreeNodeEvent LoadingChildernDone; + private void OnLoadingChildrenSQL(object sender, VETreeNodeEventArgs args) + { + if (LoadingChildrenSQL != null) LoadingChildrenSQL(sender, args); + } + private void OnLoadingChildrenMax(object sender, VETreeNodeEventArgs args) + { + if (LoadingChildernMax != null) LoadingChildernMax(sender, args); + } + private void OnLoadingChildrenValue(object sender, VETreeNodeEventArgs args) + { + if (LoadingChildernValue != null) LoadingChildernValue(sender, args); + } + private void OnLoadingChildrenDone(object sender, VETreeNodeEventArgs args) + { + if (LoadingChildernDone != null) LoadingChildernDone(sender, args); + } + #endregion + #region Business Methods + protected IVEDrillDownReadOnly _VEObject; + public IVEDrillDownReadOnly VEObject + { + get { return _VEObject; } + set + { + _VEObject = value; + base.Text = _VEObject.ToString(); + ResetNode(); + } + } + //public void Refresh() + //{ + // if (_VEObject != null) + // Text = _VEObject.ToString(); + //} + // Only load the Children Once + protected bool _ChildrenLoaded = false; + public bool ChildrenLoaded + { + get { return _ChildrenLoaded; } + } + // Reset Node + //public void CloseNode() + //{ + // ResetNode(); + //} + private void SetProperty(string name) + { + PropertyInfo propertyInfoObj = _VEObject.GetType().GetProperty(name); + if (propertyInfoObj == null) return; + PropertyInfo propertyInfoThis = this.GetType().GetProperty(name); + if (propertyInfoThis == null) return; + try + { + propertyInfoThis.SetValue(this, propertyInfoObj.GetValue(_VEObject, null), null); + } + catch (Exception ex) + { + Console.WriteLine("Error: {0}", ex.Message); + } + } + public void ResetNode() + { + if (_VEObject!=null && _VEObject.HasChildren && _ChildrenLoaded == false) + { + _ChildrenLoaded = false;// Reset the children loaded flag + this.Nodes.Add("Dummy");// Add a Dummy Node so that the item will appear to be expanable. + } + else + { + _ChildrenLoaded = true;// Reset the children loaded flag + } + if (base.Text != _VEObject.ToString()) base.Text = _VEObject.ToString(); + SetProperty("ForeColor"); + SetProperty("BackColor"); + SetProperty("ImageIndex"); + SetProperty("IsVisible"); + SetProperty("SelectedImageIndex"); + // ToDo: Need to reset object as well + } + public void RefreshNode() + { + ResetNode();// Drop Children + LoadChildren();// Load Children + } + public static VETreeNode GetFolder(int folderID) + { + VETreeNode tn = new VETreeNode(FolderInfo.Get(folderID)); + //tn.Nodes.Add("Dummy"); + tn.ResetNode(); + return tn; + } +// public abstract void LoadChildren(); + //private long _Start; + //private Dictionary _Timings=new Dictionary(); + //private void tReset() + //{ + // _Timings = new Dictionary(); + // _Start = DateTime.Now.Ticks; + //} + //private void tNext(string msg) + //{ + // long tEnd = DateTime.Now.Ticks; + // long tDiff = tEnd - _Start; + // if (_Timings.ContainsKey(msg)) tDiff += _Timings[msg]; + // _Timings[msg] = tDiff; + // _Start = DateTime.Now.Ticks; + //} + //private void tShowResults() + //{ + // Console.WriteLine("Timings"); + // long total=0; + // foreach (string msg in _Timings.Keys) + // { + // total += _Timings[msg]; + // Console.WriteLine("{0}\t\"{1}\"", TimeSpan.FromTicks(_Timings[msg]).TotalMilliseconds, msg); + // } + // Console.WriteLine("{0}\t\"Total\"", TimeSpan.FromTicks(total).TotalMilliseconds); + //} + public virtual void LoadChildren() + { + if (!_ChildrenLoaded) + { + this.Nodes.Clear(); + //tReset(); + DateTime tStart = DateTime.Now; + OnLoadingChildrenSQL(this, new VETreeNodeEventArgs()); + IList ol = _VEObject.GetChildren(); + OnLoadingChildrenMax(this, new VETreeNodeEventArgs(ol.Count)); + //tNext("GetChildren"); + if (ol != null) + { + this.TreeView.BeginUpdate(); + int icnt = 0; + foreach (IVEDrillDownReadOnly o in ol) + { + OnLoadingChildrenValue(this,new VETreeNodeEventArgs( ++icnt)); + //tNext("Cycle"); + try + { + VETreeNode tmp = new VETreeNode(o); + //tNext("Allocate VETreeNode"); + //tmp.ResetNode(); + if (o.HasChildren) + tmp.Nodes.Add("Dummy");// Add a Dummy Node so that the item will appear to be expanable. + else + tmp._ChildrenLoaded = true;// Reset the children loaded flag + //tNext("Add Children"); + this.Nodes.Add(tmp); + //tNext("Add To Nodes"); + } + catch (Exception ex) + { + Console.WriteLine("{0}\r\n{1}", ex.Message, ex.InnerException); + } + } + //} + //tNext("Set Nodes"); + this.TreeView.EndUpdate(); + //tNext("End Update"); + //tShowResults(); + } + _ChildrenLoaded = true; + OnLoadingChildrenDone(this, new VETreeNodeEventArgs(TimeSpan.FromTicks(DateTime.Now.Ticks - tStart.Ticks).TotalSeconds.ToString())); + } + } + + //public IVEReadOnlyItem GetCsla() + //{ + // return _VEObject; + //} + #endregion + #region Factory Methods + // Constructors + public VETreeNode() : base("NoText") { ; } + public VETreeNode(IVEDrillDownReadOnly o) + : base(o.ToString()) + { + _VEObject = o;// Save the BusinessObject + ResetNode(); + } + public VETreeNode(string s) + : base(s) + { + _VEObject = null;// Save the BusinessObject + //ResetNode(); + } + #endregion + } + //public class VETreeNodeBase : VETreeNode + //where T : VETreeNode, new() + //{ + // #region Factory Methods + // private static int _ICount = 0; + // public VETreeNodeBase(string s) : base(s) { ;} + // public VETreeNodeBase(IVEReadOnlyItem o) : base(o) { ;} + // protected VETreeNodeBase() : base() { + // } + // private DateTime tNext(DateTime tStart, string msg) + // { + // DateTime tEnd = DateTime.Now; + // TimeSpan ts = new TimeSpan(tEnd.Ticks-tStart.Ticks); + // Console.WriteLine("{0} - {1}", ts.TotalMilliseconds, msg); + // return tEnd; + // } + // public override void LoadChildren() + // { + // if (!_ChildrenLoaded) + // { + // this.Nodes.Clear(); + // "".TrimEnd("\r\n".ToCharArray()); + // IList ol = _VEObject.GetChildren(); + // if (ol != null) + // { + // this.TreeView.BeginUpdate(); + // DateTime tStart = DateTime.Now; + // T[] tmpa = new T[ol.Count]; + // tStart = tNext(tStart, "Allocate Array"); + // for (int i = 0; i < ol.Count; i++) tmpa[i] = new T(); + // tStart = tNext(tStart, "Allocate Nodes"); + // int ii = 0; + // foreach (IVEReadOnlyItem o in ol) + // { + // try + // { + // tmpa[ii++].VEObject = o; + // } + // catch (Exception ex) + // { + // Console.WriteLine("{0}\r\n{1}", ex.Message, ex.InnerException); + // } + // } + // tStart = tNext(tStart, "Set Nodes"); + // for (int i = 0; i < ol.Count; i++) tmpa[i].ResetNode(); + // tStart = tNext(tStart, "Reset Nodes"); + // this.Nodes.AddRange(tmpa); + // tStart = tNext(tStart, "Add Range"); + // //foreach (IVEReadOnlyItem o in ol) + // //{ + // // try + // // { + // // T tmp = new T(); + // // tmp.VEObject = o; + // // this.Nodes.Add(tmp); + // // } + // // catch (Exception ex) + // // { + // // Console.WriteLine("{0}\r\n{1}", ex.Message, ex.InnerException); + // // } + // //} + // this.TreeView.EndUpdate(); + // } + // _ChildrenLoaded = true; + // } + // } + //#endregion + //} + /* + public class VEFolder : VETreeNodeBase + { + public static VEFolder GetFolder(int folderID) + { + return new VEFolder(FolderInfo.Get(folderID)); + } + //public static VEFolder LoadTree() + //{ + // VEFolder root = null; + // FolderInfoList fil = FolderInfoList.Get(); + // Dictionary dicMissing = new Dictionary(); + // Dictionary dicExists = new Dictionary(); + // foreach (FolderInfo fi in fil) + // { + // VEFolder ftp = null; + // if (dicExists.ContainsKey(fi.ParentID)) + // { + // ftp = dicExists[fi.ParentID]; + // } + // else + // { + // if (fi.ParentID != fi.FolderID) + // { + // ftp = new VEFolder(fi.ParentID.ToString()); + // dicMissing.Add(fi.ParentID, ftp); + // dicExists.Add(fi.ParentID, ftp); + // } + // } + // VEFolder ft = null; + // if (dicMissing.ContainsKey(fi.FolderID)) + // { + // ft = dicMissing[fi.FolderID]; + // ft.VEObject = fi; + // dicMissing.Remove(fi.FolderID); + // } + // else + // { + // ft = new VEFolder(fi); + // dicExists.Add(fi.FolderID, ft); + // } + // if (fi.ParentID == fi.FolderID) + // root = ft; + // else + // ftp.Nodes.Add(ft); + // } + // //root.FindTree = dicExists; + // return root; + //} + private VEFolder(string s) : base(s) { ;} + public VEFolder(IVEReadOnlyItem o) : base(o) { ;} + } + public class VEVersion : VETreeNodeBase { } + public class VEProcedure : VETreeNodeBase + { + //public override void LoadChildren() + //{ + // if (!_ChildrenLoaded) + // { + // this.Nodes.Clear(); + // Dictionary dicSect = new Dictionary(); + // SectionInfoList ol = (SectionInfoList)_VEObject.GetChildren(); + // if (ol != null) + // { + // foreach (SectionInfo o in ol) + // { + // try + // { + // VESection tmp = new VESection(); + // tmp.VEObject = o; + // if (dicSect.ContainsKey(o.PPath)) + // dicSect[o.PPath].Nodes.Add(tmp); + // else + // this.Nodes.Add(tmp); + // dicSect[o.Path] = tmp; + // } + // catch (Exception ex) + // { + // Console.WriteLine("{0}\r\n{1}", ex.Message, ex.InnerException); + // } + // } + // } + // _ChildrenLoaded = true; + // } + //} + } + public class VESection : VETreeNodeBase { } + public class VEStep : VETreeNodeBase { } + */ + //public class VETree : VETreeNodeBase + //{ + // public VETree() { ;} + // public static VETree GetFolder(int folderID) + // { + // return new VETree(FolderInfo.Get(folderID)); + // } + // //private VEFolder(string s) : base(s) { ;} + // public VETree(IVEReadOnlyItem o) : base(o) { ;} + //} + //public class VETree : VETreeNode + //{ + // public VETree() { ;} + // public static VETree GetFolder(int folderID) + // { + // VETree tn = new VETree(FolderInfo.Get(folderID)); + // tn.ResetNode(); + // return tn; + // } + // //private VEFolder(string s) : base(s) { ;} + // public VETree(IVEReadOnlyItem o) : base(o) { ;} + // private DateTime tNext(DateTime tStart, string msg) + // { + // DateTime tEnd = DateTime.Now; + // TimeSpan ts = new TimeSpan(tEnd.Ticks - tStart.Ticks); + // Console.WriteLine("{0} - {1}", ts.TotalMilliseconds, msg); + // return tEnd; + // } + // public override void LoadChildren() + // { + // if (!_ChildrenLoaded) + // { + // this.Nodes.Clear(); + // "".TrimEnd("\r\n".ToCharArray()); + // IList ol = _VEObject.GetChildren(); + // if (ol != null) + // { + // this.TreeView.BeginUpdate(); + // DateTime tStart = DateTime.Now; + // //VETree[] tmpa = new VETree[ol.Count]; + // //tStart = tNext(tStart, "Allocate Array"); + // ////for (int i = 0; i < ol.Count; i++) tmpa[i] = new VETree(); + // ////tStart = tNext(tStart, "Allocate Nodes"); + // //int ii = 0; + // //foreach (IVEReadOnlyItem o in ol) + // //{ + // // try + // // { + // // tmpa[ii++] = new VETree(o); + // // //tmpa[ii++].VEObject = o; + // // } + // // catch (Exception ex) + // // { + // // Console.WriteLine("{0}\r\n{1}", ex.Message, ex.InnerException); + // // } + // //} + // //tStart = tNext(tStart, "Set Nodes"); + // //for (int i = 0; i < ol.Count; i++) tmpa[i].ResetNode(); + // //tStart = tNext(tStart, "Reset Nodes"); + // //this.Nodes.AddRange(tmpa); + // //tStart = tNext(tStart, "Add Range"); + // this.TreeView.DrawMode = TreeViewDrawMode.OwnerDrawAll; + // foreach (IVEReadOnlyItem o in ol) + // { + // try + // { + // VETree tmp = new VETree(o); + // //tmp.VEObject = o; + // this.Nodes.Add(tmp); + // } + // catch (Exception ex) + // { + // Console.WriteLine("{0}\r\n{1}", ex.Message, ex.InnerException); + // } + // } + // tStart = tNext(tStart, "Set Nodes"); + // this.TreeView.DrawMode = TreeViewDrawMode.Normal; + // tStart = tNext(tStart, "DrawMode"); + // this.TreeView.EndUpdate(); + // tStart = tNext(tStart, "End Update"); + // this.TreeView.Refresh(); + // tStart = tNext(tStart, "Refresh"); + // } + // _ChildrenLoaded = true; + // } + // } + //} +} diff --git a/PROMS/VEPROMS.CSLA.Library/VEPROMS.CSLA.Library.csproj b/PROMS/VEPROMS.CSLA.Library/VEPROMS.CSLA.Library.csproj new file mode 100644 index 00000000..71e8deff --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/VEPROMS.CSLA.Library.csproj @@ -0,0 +1,209 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {41B2D786-1C03-4C1A-9247-DA9F0D6B06D5} + Library + Properties + VEPROMS.CSLA.Library + VEPROMS.CSLA.Library + SAK + SAK + SAK + SAK + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + F:\CSLA\csla20cs-2.1.4-070223\csla20cs\csla20cs\Csla\bin\Debug\Csla.dll + + + False + F:\Log4Net\log4net-1.2.10\bin\net\2.0\debug\log4net.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PROMS/VEPROMS.CSLA.Library/VEPROMS.CSLA.Library.csproj.vspscc b/PROMS/VEPROMS.CSLA.Library/VEPROMS.CSLA.Library.csproj.vspscc new file mode 100644 index 00000000..b6d32892 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/VEPROMS.CSLA.Library.csproj.vspscc @@ -0,0 +1,10 @@ +"" +{ +"FILE_VERSION" = "9237" +"ENLISTMENT_CHOICE" = "NEVER" +"PROJECT_FILE_RELATIVE_PATH" = "" +"NUMBER_OF_EXCLUDED_FILES" = "0" +"ORIGINAL_PROJECT_FILE_PATH" = "" +"NUMBER_OF_NESTED_PROJECTS" = "0" +"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER" +}