using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using GZTW.AyaNova.BLL; using Infragistics.Win; using Infragistics.Win.UltraWinGrid; using System.Reflection; using log4net; namespace AyaNova { /// /// Summary description for GlobalSettingsForm. /// public class GlobalSettingsForm : System.Windows.Forms.Form { // Create a logger for use in this class //case 1039 private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private System.Windows.Forms.ErrorProvider ErrorProvider; private Infragistics.Win.UltraWinToolbars.UltraToolbarsManager tbManager; private Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea _GlobalSettingsForm_Toolbars_Dock_Area_Left; private Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea _GlobalSettingsForm_Toolbars_Dock_Area_Right; private Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea _GlobalSettingsForm_Toolbars_Dock_Area_Top; private Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea _GlobalSettingsForm_Toolbars_Dock_Area_Bottom; private System.Windows.Forms.PropertyGrid pGrid; private System.ComponentModel.IContainer components; private System.Windows.Forms.HelpProvider helpProvider1; private PropertyBag bag; bool full = !AyaBizUtils.Lite; public GlobalSettingsForm() { // // Required for Windows Form Designer support // InitializeComponent(); bag = new PropertyBag(); bag.GetValue += new PropertySpecEventHandler(this.bag_GetValue); bag.SetValue += new PropertySpecEventHandler(this.bag_SetValue); } /// /// Clean up any resources being used. /// protected override void Dispose(bool disposing) { if (disposing) { if (components != null) { components.Dispose(); } } base.Dispose(disposing); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.components = new System.ComponentModel.Container(); Infragistics.Win.UltraWinToolbars.UltraToolbar ultraToolbar1 = new Infragistics.Win.UltraWinToolbars.UltraToolbar("GlobalSettingsMenuBar"); Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool1 = new Infragistics.Win.UltraWinToolbars.ButtonTool("LT:UI.Command.RecordHistory"); Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool2 = new Infragistics.Win.UltraWinToolbars.ButtonTool("LT:UI.Command.Save"); Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool3 = new Infragistics.Win.UltraWinToolbars.ButtonTool("LT:UI.Command.Cancel"); Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool7 = new Infragistics.Win.UltraWinToolbars.ButtonTool("LT:UI.Toolbar.Refresh"); Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool4 = new Infragistics.Win.UltraWinToolbars.ButtonTool("LT:UI.Command.RecordHistory"); Infragistics.Win.Appearance appearance1 = new Infragistics.Win.Appearance(); Infragistics.Win.Appearance appearance2 = new Infragistics.Win.Appearance(); Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool5 = new Infragistics.Win.UltraWinToolbars.ButtonTool("LT:UI.Command.Save"); Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool6 = new Infragistics.Win.UltraWinToolbars.ButtonTool("LT:UI.Command.Cancel"); Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool8 = new Infragistics.Win.UltraWinToolbars.ButtonTool("LT:UI.Toolbar.Refresh"); Infragistics.Win.Appearance appearance3 = new Infragistics.Win.Appearance(); Infragistics.Win.Appearance appearance4 = new Infragistics.Win.Appearance(); this.pGrid = new System.Windows.Forms.PropertyGrid(); this.ErrorProvider = new System.Windows.Forms.ErrorProvider(this.components); this.tbManager = new Infragistics.Win.UltraWinToolbars.UltraToolbarsManager(this.components); this._GlobalSettingsForm_Toolbars_Dock_Area_Left = new Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea(); this._GlobalSettingsForm_Toolbars_Dock_Area_Right = new Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea(); this._GlobalSettingsForm_Toolbars_Dock_Area_Top = new Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea(); this._GlobalSettingsForm_Toolbars_Dock_Area_Bottom = new Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea(); this.helpProvider1 = new System.Windows.Forms.HelpProvider(); ((System.ComponentModel.ISupportInitialize)(this.ErrorProvider)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.tbManager)).BeginInit(); this.SuspendLayout(); // // pGrid // this.pGrid.LineColor = System.Drawing.SystemColors.ScrollBar; this.pGrid.Location = new System.Drawing.Point(0, 78); this.pGrid.Name = "pGrid"; this.pGrid.Size = new System.Drawing.Size(941, 688); this.pGrid.TabIndex = 0; this.pGrid.ToolbarVisible = false; // // ErrorProvider // this.ErrorProvider.ContainerControl = this; // // tbManager // this.tbManager.DesignerFlags = 1; this.tbManager.DockWithinContainer = this; this.tbManager.DockWithinContainerBaseType = typeof(System.Windows.Forms.Form); this.tbManager.ShowFullMenusDelay = 500; ultraToolbar1.DockedColumn = 0; ultraToolbar1.DockedRow = 0; ultraToolbar1.NonInheritedTools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] { buttonTool1, buttonTool2, buttonTool3, buttonTool7}); ultraToolbar1.Text = "GlobalSettingsMenuBar"; this.tbManager.Toolbars.AddRange(new Infragistics.Win.UltraWinToolbars.UltraToolbar[] { ultraToolbar1}); this.tbManager.ToolbarSettings.AllowCustomize = Infragistics.Win.DefaultableBoolean.False; this.tbManager.ToolbarSettings.AllowFloating = Infragistics.Win.DefaultableBoolean.False; this.tbManager.ToolbarSettings.AllowHiding = Infragistics.Win.DefaultableBoolean.False; appearance1.Image = global::AyaNova.Resource1.RecordHistory32; buttonTool4.SharedPropsInternal.AppearancesLarge.Appearance = appearance1; appearance2.Image = global::AyaNova.Resource1.RecordHistory16; buttonTool4.SharedPropsInternal.AppearancesSmall.Appearance = appearance2; buttonTool4.SharedPropsInternal.Caption = "LT:UI.Command.RecordHistory"; buttonTool5.SharedPropsInternal.Caption = "LT:UI.Command.Save"; buttonTool5.SharedPropsInternal.DisplayStyle = Infragistics.Win.UltraWinToolbars.ToolDisplayStyle.TextOnlyAlways; buttonTool6.SharedPropsInternal.Caption = "LT:UI.Command.Cancel"; buttonTool6.SharedPropsInternal.DisplayStyle = Infragistics.Win.UltraWinToolbars.ToolDisplayStyle.TextOnlyAlways; appearance3.Image = global::AyaNova.Resource1.Refresh32; buttonTool8.SharedPropsInternal.AppearancesLarge.Appearance = appearance3; appearance4.Image = global::AyaNova.Resource1.Refresh16; buttonTool8.SharedPropsInternal.AppearancesSmall.Appearance = appearance4; buttonTool8.SharedPropsInternal.Caption = "LT:UI.Toolbar.Refresh"; buttonTool8.SharedPropsInternal.DisplayStyle = Infragistics.Win.UltraWinToolbars.ToolDisplayStyle.ImageAndText; this.tbManager.Tools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] { buttonTool4, buttonTool5, buttonTool6, buttonTool8}); this.tbManager.UseLargeImagesOnToolbar = true; this.tbManager.ToolClick += new Infragistics.Win.UltraWinToolbars.ToolClickEventHandler(this.tbManager_ToolClick); // // _GlobalSettingsForm_Toolbars_Dock_Area_Left // this._GlobalSettingsForm_Toolbars_Dock_Area_Left.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping; this._GlobalSettingsForm_Toolbars_Dock_Area_Left.BackColor = System.Drawing.SystemColors.Control; this._GlobalSettingsForm_Toolbars_Dock_Area_Left.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Left; this._GlobalSettingsForm_Toolbars_Dock_Area_Left.ForeColor = System.Drawing.SystemColors.ControlText; this._GlobalSettingsForm_Toolbars_Dock_Area_Left.Location = new System.Drawing.Point(0, 43); this._GlobalSettingsForm_Toolbars_Dock_Area_Left.Name = "_GlobalSettingsForm_Toolbars_Dock_Area_Left"; this._GlobalSettingsForm_Toolbars_Dock_Area_Left.Size = new System.Drawing.Size(0, 621); this._GlobalSettingsForm_Toolbars_Dock_Area_Left.ToolbarsManager = this.tbManager; // // _GlobalSettingsForm_Toolbars_Dock_Area_Right // this._GlobalSettingsForm_Toolbars_Dock_Area_Right.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping; this._GlobalSettingsForm_Toolbars_Dock_Area_Right.BackColor = System.Drawing.SystemColors.Control; this._GlobalSettingsForm_Toolbars_Dock_Area_Right.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Right; this._GlobalSettingsForm_Toolbars_Dock_Area_Right.ForeColor = System.Drawing.SystemColors.ControlText; this._GlobalSettingsForm_Toolbars_Dock_Area_Right.Location = new System.Drawing.Point(888, 43); this._GlobalSettingsForm_Toolbars_Dock_Area_Right.Name = "_GlobalSettingsForm_Toolbars_Dock_Area_Right"; this._GlobalSettingsForm_Toolbars_Dock_Area_Right.Size = new System.Drawing.Size(0, 621); this._GlobalSettingsForm_Toolbars_Dock_Area_Right.ToolbarsManager = this.tbManager; // // _GlobalSettingsForm_Toolbars_Dock_Area_Top // this._GlobalSettingsForm_Toolbars_Dock_Area_Top.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping; this._GlobalSettingsForm_Toolbars_Dock_Area_Top.BackColor = System.Drawing.SystemColors.Control; this._GlobalSettingsForm_Toolbars_Dock_Area_Top.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Top; this._GlobalSettingsForm_Toolbars_Dock_Area_Top.ForeColor = System.Drawing.SystemColors.ControlText; this._GlobalSettingsForm_Toolbars_Dock_Area_Top.Location = new System.Drawing.Point(0, 0); this._GlobalSettingsForm_Toolbars_Dock_Area_Top.Name = "_GlobalSettingsForm_Toolbars_Dock_Area_Top"; this._GlobalSettingsForm_Toolbars_Dock_Area_Top.Size = new System.Drawing.Size(888, 43); this._GlobalSettingsForm_Toolbars_Dock_Area_Top.ToolbarsManager = this.tbManager; // // _GlobalSettingsForm_Toolbars_Dock_Area_Bottom // this._GlobalSettingsForm_Toolbars_Dock_Area_Bottom.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping; this._GlobalSettingsForm_Toolbars_Dock_Area_Bottom.BackColor = System.Drawing.SystemColors.Control; this._GlobalSettingsForm_Toolbars_Dock_Area_Bottom.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Bottom; this._GlobalSettingsForm_Toolbars_Dock_Area_Bottom.ForeColor = System.Drawing.SystemColors.ControlText; this._GlobalSettingsForm_Toolbars_Dock_Area_Bottom.Location = new System.Drawing.Point(0, 664); this._GlobalSettingsForm_Toolbars_Dock_Area_Bottom.Name = "_GlobalSettingsForm_Toolbars_Dock_Area_Bottom"; this._GlobalSettingsForm_Toolbars_Dock_Area_Bottom.Size = new System.Drawing.Size(888, 0); this._GlobalSettingsForm_Toolbars_Dock_Area_Bottom.ToolbarsManager = this.tbManager; // // GlobalSettingsForm // this.AutoScaleBaseSize = new System.Drawing.Size(6, 15); this.ClientSize = new System.Drawing.Size(888, 664); this.ControlBox = false; this.Controls.Add(this.pGrid); this.Controls.Add(this._GlobalSettingsForm_Toolbars_Dock_Area_Left); this.Controls.Add(this._GlobalSettingsForm_Toolbars_Dock_Area_Right); this.Controls.Add(this._GlobalSettingsForm_Toolbars_Dock_Area_Bottom); this.Controls.Add(this._GlobalSettingsForm_Toolbars_Dock_Area_Top); this.helpProvider1.SetHelpKeyword(this, ""); this.helpProvider1.SetHelpNavigator(this, System.Windows.Forms.HelpNavigator.Topic); this.MinimumSize = new System.Drawing.Size(900, 563); this.Name = "GlobalSettingsForm"; this.helpProvider1.SetShowHelp(this, true); this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show; this.Closing += new System.ComponentModel.CancelEventHandler(this.GlobalSettingsForm_Closing); this.Load += new System.EventHandler(this.GlobalSettingsForm_Load); ((System.ComponentModel.ISupportInitialize)(this.ErrorProvider)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.tbManager)).EndInit(); this.ResumeLayout(false); } #endregion // __ _ _ ___ ____ __ __ __ __ __ ___ ___ // / _)( )( )/ __)(_ _)/ \( \/ ) / _)/ \( \( _) // ( (_ )()( \__ \ )( ( () )) ( ( (_( () )) ) )) _) // \__) \__/ (___/ (__) \__/(_/\/\_) \__)\__/(___/(___) // #region Form Load / Close //variable to hold user form settings //UIUserFormSetting mFormSetting; /// /// Prepare the form /// /// /// private void GlobalSettingsForm_Load(object sender, System.EventArgs e) { //case 1438 diagnosis pGrid.Dock = DockStyle.Fill; //case 1039 //log.Debug("GlobalSettingsForm_Load"); // // helpProvider1 // this.helpProvider1.HelpNamespace = Util.BaseHelpUrl + "global_settings.htm"; Cursor.Current = Cursors.WaitCursor; this.Visible = false; //See if user has any rights to be here... //(this is done here to ensure that no matter what happens if a user has no rights they can't get here //useful in case we miss a way of getting to a Global edit screen from elsewhere in the program) if (AyaBizUtils.Right("Object.Global") < (int)SecurityLevelTypes.ReadOnly)//Less than read only instead of NoAccess to catch records where it's zero instead of 1 { //Inform them of their wicked ways and boot them out of here... MessageBox.Show(string.Format( Util.LocaleText.GetLocalizedText("Error.Security.NotAuthorizedToRetrieve"), Util.LocaleText.GetLocalizedText("O.Global"))); this.Close(); return; } InitializePropertyGrid(); Util.LocalizeHelperInsertMenu(tbManager, this); //case 1810 Util.Localize(this); //restrict UI based on security settings RestrictUI(); Util.LoadFormCustomization("GlobalSettings", this, tbManager, true); Util.PluginInsertMenu(tbManager, new Util.PluginMenuOptionData(true, RootObjectTypes.Global, mGlobal, null));//case 941 Cursor.Current = Cursors.Default; //====================================== //Nifty way to set splitter where we want by percentage... PropertyInfo controlsProp = pGrid.GetType().GetProperty("Controls"); System.Windows.Forms.Control.ControlCollection cc = controlsProp.GetValue(pGrid, null) as System.Windows.Forms.Control.ControlCollection; foreach (Control c in cc) { if (c.GetType().Name == "PropertyGridView") { MethodInfo mst = c.GetType().GetMethod("MoveSplitterTo", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly); PropertyInfo widthProp = c.GetType().GetProperty("Width"); int width = (int)widthProp.GetValue(c, null); double newwidth = width * 0.25;//<-this is a bit larger than necessary for English //leaving a bit of extra room for non-english longer text mst.Invoke(c, new object[] { (int)newwidth }); break; } } //============ Application.Idle += new EventHandler(Application_Idle); this.Visible = true; } /// /// Used to track whether the close was done by the program /// or done by the user clicking on the upper left corner X control /// bool bClosingHandled = false; /// /// Save form layout and grid layout for next time /// /// /// private void GlobalSettingsForm_Closing(object sender, System.ComponentModel.CancelEventArgs e) { //case 1039 //log.Debug("GlobalSettingsForm_Closing"); if (!bClosingHandled) { //Save record if necessary //User really can't cancel edit as this form //is closing with the whole app, so just stop the edit //and exit gracefully as possible if (!RecordUpdate(RecordActionType.PromptToSave)) { mGlobal.CancelEdit(); } } Application.Idle -= new EventHandler(Application_Idle); Util.SaveFormCustomization("GlobalSettings", this, tbManager, true); } #endregion #region PropertyGrid private void InitializePropertyGrid() { //case 1436 bag.Properties.Clear(); //case 1039 //log.Debug("InitializePropertyGrid"); //case 3563 - these aren't used, don't work and shouldn't be showing //if (full) // bag.Properties.Add(new PropertySpec("GoToAddress", Util.LocaleText.GetLocalizedText("Address.Label.AddressType.Physical"), typeof(GZTW.AyaNova.BLL.Address), "COMPANY INFO", Util.LocaleText.GetLocalizedText("Address.Label.AddressType.Physical.Description"), "")); //if (full) // bag.Properties.Add(new PropertySpec("MailToAddress", Util.LocaleText.GetLocalizedText("Address.Label.AddressType.Postal"), typeof(GZTW.AyaNova.BLL.Address), "COMPANY INFO", Util.LocaleText.GetLocalizedText("Address.Label.AddressType.Postal.Description"), "")); ////bag.Properties.Add(new PropertySpec("AllowScheduleConflicts",Util.LocaleText.GetLocalizedText("Global.Label.AllowScheduleConflicts"),typeof(bool),"GLOBAL SETTINGS",Util.LocaleText.GetLocalizedText("Global.Label.AllowScheduleConflicts.Description"),true)); //bag.Properties.Add(new PropertySpec("UseRegions",Util.LocaleText.GetLocalizedText("Global.Label.UseRegions"),typeof(bool),"GLOBAL SETTINGS",Util.LocaleText.GetLocalizedText("Global.Label.UseRegions.Description"),false)); bag.Properties.Add(new PropertySpec("DefaultLanguage", Util.LocaleText.GetLocalizedText("Global.Label.DefaultLanguage"), typeof(string), "LANGUAGE SETTINGS", Util.LocaleText.GetLocalizedText("Global.Label.DefaultLanguage.Description"), "English", null, typeof(LocaleConverter))); //Tax codes if (full) bag.Properties.Add(new PropertySpec("TaxPartPurchaseID", Util.LocaleText.GetLocalizedText("Global.Label.TaxPartPurchaseID"), typeof(Guid), "BUSINESS SETTINGS", Util.LocaleText.GetLocalizedText("Global.Label.TaxPartPurchaseID.Description"), Guid.Empty, null, typeof(TaxCodeIDConverter))); bag.Properties.Add(new PropertySpec("TaxPartSaleID", Util.LocaleText.GetLocalizedText("Global.Label.TaxPartSaleID"), typeof(Guid), "BUSINESS SETTINGS", Util.LocaleText.GetLocalizedText("Global.Label.TaxPartSaleID.Description"), Guid.Empty, null, typeof(TaxCodeIDConverter))); bag.Properties.Add(new PropertySpec("TaxRateSaleID", Util.LocaleText.GetLocalizedText("Global.Label.TaxRateSaleID"), typeof(Guid), "BUSINESS SETTINGS", Util.LocaleText.GetLocalizedText("Global.Label.TaxRateSaleID.Description"), Guid.Empty, null, typeof(TaxCodeIDConverter))); //template if (full) bag.Properties.Add(new PropertySpec("DefaultServiceTemplateID", Util.LocaleText.GetLocalizedText("O.WorkorderServiceTemplate"), typeof(Guid), "BUSINESS SETTINGS", Util.LocaleText.GetLocalizedText("Global.Label.DefaultServiceTemplateID.Description"), Guid.Empty, null, typeof(TemplateConverter))); //Default workorder closed status if (full) bag.Properties.Add(new PropertySpec("DefaultClosedWorkorderStatus", Util.LocaleText.GetLocalizedText("Global.Label.WorkorderClosedStatus"), typeof(Guid), "BUSINESS SETTINGS", Util.LocaleText.GetLocalizedText("Global.Label.WorkorderClosedStatus.Description"), Guid.Empty, null, typeof(WorkorderStatusConverter))); bag.Properties.Add(new PropertySpec("WorkorderNumberStartSeed", Util.LocaleText.GetLocalizedText("Global.Label.WorkorderNumberStartSeed"), typeof(int), "BUSINESS SETTINGS", Util.LocaleText.GetLocalizedText("Global.Label.WorkorderNumberStartSeed.Description"), 1)); if (full) bag.Properties.Add(new PropertySpec("PurchaseOrderStartSeed", Util.LocaleText.GetLocalizedText("Global.Label.PurchaseOrderStartSeed"), typeof(int), "BUSINESS SETTINGS", Util.LocaleText.GetLocalizedText("Global.Label.PurchaseOrderStartSeed.Description"), 1)); if (full) bag.Properties.Add(new PropertySpec("QuoteNumberStartSeed", Util.LocaleText.GetLocalizedText("Global.Label.QuoteNumberStartSeed"), typeof(int), "BUSINESS SETTINGS", Util.LocaleText.GetLocalizedText("Global.Label.QuoteNumberStartSeed.Description"), 1)); if (full) bag.Properties.Add(new PropertySpec("InventoryAdjustmentStartSeed", Util.LocaleText.GetLocalizedText("Global.Label.InventoryAdjustmentStartSeed"), typeof(int), "BUSINESS SETTINGS", Util.LocaleText.GetLocalizedText("Global.Label.InventoryAdjustmentStartSeed.Description"), 1)); bag.Properties.Add(new PropertySpec("WorkorderSummaryTemplate", Util.LocaleText.GetLocalizedText("Global.Label.WorkorderSummaryTemplate"), typeof(string), "DISPLAY SETTINGS", Util.LocaleText.GetLocalizedText("Global.Label.WorkorderSummaryTemplate.Description"), "", typeof(Util.WorkorderTemplateEditor), null)); if (full) bag.Properties.Add(new PropertySpec("UseInventory", Util.LocaleText.GetLocalizedText("Global.Label.UseInventory"), typeof(bool), "GLOBAL SETTINGS", Util.LocaleText.GetLocalizedText("Global.Label.UseInventory.Description"), false)); //case 1487 if (full) bag.Properties.Add(new PropertySpec("MainGridAutoRefresh", Util.LocaleText.GetLocalizedText("Global.Label.MainGridAutoRefresh"), typeof(bool), "GLOBAL SETTINGS", Util.LocaleText.GetLocalizedText("Global.Label.MainGridAutoRefresh.Description"), false)); bag.Properties.Add(new PropertySpec("CJKIndex", Util.LocaleText.GetLocalizedText("Global.Label.CJKIndex"), typeof(bool), "LANGUAGE SETTINGS", Util.LocaleText.GetLocalizedText("Global.Label.CJKIndex.Description"), false)); if (full) bag.Properties.Add(new PropertySpec("DefaultUnitNameDisplayFormat", Util.LocaleText.GetLocalizedText("Global.Label.DefaultUnitNameDisplayFormat"), typeof(UnitNameDisplayFormats), "DISPLAY SETTINGS", Util.LocaleText.GetLocalizedText("Global.Label.UnitNameDisplayFormats.Description"), UnitNameDisplayFormats.SerialOnly, null, typeof(Util.EnumDescConverter))); bag.Properties.Add(new PropertySpec("DefaultScheduleableUserNameDisplayFormat", Util.LocaleText.GetLocalizedText("Global.Label.DefaultScheduleableUserNameDisplayFormat"), typeof(ScheduleableUserNameDisplayFormats), "DISPLAY SETTINGS", Util.LocaleText.GetLocalizedText("Global.Label.DefaultScheduleableUserNameDisplayFormat.Description"), ScheduleableUserNameDisplayFormats.FirstLast, null, typeof(Util.EnumDescConverter))); bag.Properties.Add(new PropertySpec("DefaultPartDisplayFormat", Util.LocaleText.GetLocalizedText("Global.Label.DefaultPartDisplayFormat"), typeof(PartDisplayFormats), "DISPLAY SETTINGS", Util.LocaleText.GetLocalizedText("Global.Label.DefaultPartDisplayFormat.Description"), PartDisplayFormats.NumberName, null, typeof(Util.EnumDescConverter))); if (full) bag.Properties.Add(new PropertySpec("WorkorderCloseByAge", Util.LocaleText.GetLocalizedText("Global.Label.WorkorderCloseByAge"), typeof(int), "BUSINESS SETTINGS", Util.LocaleText.GetLocalizedText("Global.Label.WorkorderCloseByAge.Description"), 0)); if (full) { bag.Properties.Add(new PropertySpec("UseNotification", Util.LocaleText.GetLocalizedText("Global.Label.UseNotification"), typeof(bool), "NOTIFICATION", Util.LocaleText.GetLocalizedText("Global.Label.UseNotification.Description"), false)); bag.Properties.Add(new PropertySpec("NotifySMTPHost", Util.LocaleText.GetLocalizedText("Global.Label.NotifySMTPHost"), typeof(string), "NOTIFICATION", Util.LocaleText.GetLocalizedText("Global.Label.NotifySMTPHost.Description"), "mail.yourserver.com")); bag.Properties.Add(new PropertySpec("NotifySMTPAccount", Util.LocaleText.GetLocalizedText("Global.Label.NotifySMTPAccount"), typeof(string), "NOTIFICATION", Util.LocaleText.GetLocalizedText("Global.Label.NotifySMTPAccount.Description"), "senderaccount@yourserver.com")); bag.Properties.Add(new PropertySpec("NotifySMTPPassword", Util.LocaleText.GetLocalizedText("Global.Label.NotifySMTPPassword"), typeof(string), "NOTIFICATION", Util.LocaleText.GetLocalizedText("Global.Label.NotifySMTPPassword.Description"), "senderaccountpassword")); bag.Properties.Add(new PropertySpec("NotifySMTPFrom", Util.LocaleText.GetLocalizedText("Global.Label.NotifySMTPFrom"), typeof(string), "NOTIFICATION", Util.LocaleText.GetLocalizedText("Global.Label.NotifySMTPFrom.Description"), "fromaddress@yourserver.com")); //case 1136 bag.Properties.Add(new PropertySpec("NotifySMTPEncryptionMethod", Util.LocaleText.GetLocalizedText("Global.Label.SMTPEncryption"), typeof(string), "NOTIFICATION", Util.LocaleText.GetLocalizedText("Global.Label.SMTPEncryption.Description"), "")); //case 1382 bag.Properties.Add(new PropertySpec("SMTPRetry", Util.LocaleText.GetLocalizedText("Global.Label.SMTPRetry"), typeof(bool), "NOTIFICATION", Util.LocaleText.GetLocalizedText("Global.Label.SMTPRetry.Description"), false)); } bag.Properties.Add(new PropertySpec("CoordinateStyle", Util.LocaleText.GetLocalizedText("Global.Label.CoordinateStyle"), typeof(CoordinateTypes), "DISPLAY SETTINGS", Util.LocaleText.GetLocalizedText("Global.Label.CoordinateStyle.Description"), CoordinateTypes.DegreesDecimalMinutes, null, typeof(Util.EnumDescConverter))); bag.Properties.Add(new PropertySpec("DefaultLatitude", Util.LocaleText.GetLocalizedText("Global.Label.DefaultLatitude"), typeof(LatitudeHemisphere), "DISPLAY SETTINGS", Util.LocaleText.GetLocalizedText("Global.Label.DefaultLatitude.Description"), LatitudeHemisphere.North, null, typeof(Util.EnumDescConverter))); bag.Properties.Add(new PropertySpec("DefaultLongitude", Util.LocaleText.GetLocalizedText("Global.Label.DefaultLongitude"), typeof(LongitudeHemisphere), "DISPLAY SETTINGS", Util.LocaleText.GetLocalizedText("Global.Label.DefaultLongitude.Description"), LongitudeHemisphere.West, null, typeof(Util.EnumDescConverter))); //case 73 if (full) bag.Properties.Add(new PropertySpec("MaxFileSizeMB", Util.LocaleText.GetLocalizedText("Global.Label.MaxFileSizeMB"), typeof(int), "BUSINESS SETTINGS", Util.LocaleText.GetLocalizedText("Global.Label.MaxFileSizeMB.Description"), 50)); //case 816 bag.Properties.Add(new PropertySpec("LaborSchedUserDfltTimeSpan", Util.LocaleText.GetLocalizedText("Global.Label.LaborSchedUserDfltTimeSpan"), typeof(int), "BUSINESS SETTINGS", Util.LocaleText.GetLocalizedText("Global.Label.LaborSchedUserDfltTimeSpan.Description"), 60)); if (full) bag.Properties.Add(new PropertySpec("TravelDfltTimeSpan", Util.LocaleText.GetLocalizedText("Global.Label.TravelDfltTimeSpan"), typeof(int), "BUSINESS SETTINGS", Util.LocaleText.GetLocalizedText("Global.Label.TravelDfltTimeSpan.Description"), 60)); //case 1392 SchedUserNonTodayStartTime bag.Properties.Add(new PropertySpec("SchedUserNonTodayStartTime", Util.LocaleText.GetLocalizedText("Global.Label.SchedUserNonTodayStartTime"), typeof(string), "BUSINESS SETTINGS", Util.LocaleText.GetLocalizedText("Global.Label.SchedUserNonTodayStartTime.Description"), "", null, null)); if (full)//case 1346 { bag.Properties.Add(new PropertySpec("SignatureTitle", Util.LocaleText.GetLocalizedText("Global.Label.SignatureTitle"), typeof(string), "SIGNATURE", Util.LocaleText.GetLocalizedText("Global.Label.SignatureTitle.Description"), "Please sign below")); bag.Properties.Add(new PropertySpec("SignatureHeader", Util.LocaleText.GetLocalizedText("Global.Label.SignatureHeader"), typeof(string), "SIGNATURE", Util.LocaleText.GetLocalizedText("Global.Label.SignatureHeader.Description"), "By signing below you agree to terms for service provided")); bag.Properties.Add(new PropertySpec("SignatureFooter", Util.LocaleText.GetLocalizedText("Global.Label.SignatureFooter"), typeof(string), "SIGNATURE", Util.LocaleText.GetLocalizedText("Global.Label.SignatureFooter.Description"), "")); } pGrid.SelectedObject = bag; } //Get / set values of property bag private void bag_GetValue(object sender, PropertySpecEventArgs e) { switch (e.Property.Key) { case "GoToAddress": e.Value = mGlobal.GoToAddress; break; case "MailToAddress": e.Value = mGlobal.MailToAddress; break; //case "AllowScheduleConflicts": e.Value = mGlobal.AllowScheduleConflicts; break; //case "UseRegions": e.Value = mGlobal.UseRegions; break; case "DefaultLanguage": e.Value = mGlobal.DefaultLanguage; break; case "TaxPartPurchaseID": e.Value = mGlobal.TaxPartPurchaseID; break; case "TaxPartSaleID": e.Value = mGlobal.TaxPartSaleID; break; case "TaxRateSaleID": e.Value = mGlobal.TaxRateSaleID; break; case "DefaultServiceTemplateID": e.Value = mGlobal.DefaultServiceTemplateID; break; case "WorkorderNumberStartSeed": e.Value = mGlobal.WorkorderNumberStartSeed; break; case "PurchaseOrderStartSeed": e.Value = mGlobal.PurchaseOrderStartSeed; break; case "QuoteNumberStartSeed": e.Value = mGlobal.QuoteNumberStartSeed; break; case "InventoryAdjustmentStartSeed": e.Value = mGlobal.InventoryAdjustmentStartSeed; break; case "WorkorderSummaryTemplate": e.Value = mGlobal.WorkorderSummaryTemplate; break; case "UseInventory": e.Value = mGlobal.UseInventory; break; case "MainGridAutoRefresh": e.Value = mGlobal.MainGridAutoRefresh; break;//case 1487 case "CJKIndex": e.Value = mGlobal.CJKIndex; break; case "DefaultUnitNameDisplayFormat": e.Value = mGlobal.DefaultUnitNameDisplayFormat; break; case "DefaultScheduleableUserNameDisplayFormat": e.Value = mGlobal.DefaultScheduleableUserNameDisplayFormat; break; case "DefaultPartDisplayFormat": e.Value = mGlobal.DefaultPartDisplayFormat; break; case "WorkorderCloseByAge": e.Value = mGlobal.WorkorderCloseByAge; break; case "UseNotification": e.Value = mGlobal.UseNotification; break; case "NotifySMTPHost": e.Value = mGlobal.NotifySMTPHost; break; case "NotifySMTPAccount": e.Value = mGlobal.NotifySMTPAccount; break; case "NotifySMTPPassword": e.Value = mGlobal.NotifySMTPPassword; break; case "NotifySMTPFrom": e.Value = mGlobal.NotifySMTPFrom; break; //case 1136 case "NotifySMTPEncryptionMethod": e.Value = mGlobal.NotifySMTPEncryptionMethod; break; //case 1382 case "SMTPRetry": e.Value = mGlobal.SMTPRetry; break; case "CoordinateStyle": e.Value = mGlobal.CoordinateStyle; break; case "DefaultLatitude": e.Value = mGlobal.DefaultLatitude; break; case "DefaultLongitude": e.Value = mGlobal.DefaultLongitude; break; case "DefaultClosedWorkorderStatus": e.Value = mGlobal.WorkorderClosedStatus; break; case "MaxFileSizeMB": e.Value = mGlobal.MaxFileSizeMB; break;//case 73 case "TravelDfltTimeSpan": e.Value = mGlobal.TravelDfltTimeSpan; break;//case 816 case "LaborSchedUserDfltTimeSpan": e.Value = mGlobal.LaborSchedUserDfltTimeSpan; break;//case 816 case "SchedUserNonTodayStartTime": e.Value = mGlobal.SchedUserNonTodayStartTime; break;//case 1392 case "SignatureTitle": e.Value = mGlobal.SignatureTitle; break;//case 1346 case "SignatureHeader": e.Value = mGlobal.SignatureHeader; break;//case 1346 case "SignatureFooter": e.Value = mGlobal.SignatureFooter; break;//case 1346 } } private void bag_SetValue(object sender, PropertySpecEventArgs e) { switch (e.Property.Key) { //case "AllowScheduleConflicts":{mGlobal.AllowScheduleConflicts=(bool)e.Value;}break; //case "UseRegions":{mGlobal.UseRegions=(bool)e.Value;}break; case "DefaultLanguage": { mGlobal.DefaultLanguage = (string)e.Value; } break; case "TaxPartPurchaseID": { mGlobal.TaxPartPurchaseID = (Guid)e.Value; } break; case "TaxPartSaleID": { mGlobal.TaxPartSaleID = (Guid)e.Value; } break; case "TaxRateSaleID": { mGlobal.TaxRateSaleID = (Guid)e.Value; } break; case "DefaultServiceTemplateID": { mGlobal.DefaultServiceTemplateID = (Guid)e.Value; } break; case "WorkorderNumberStartSeed": { int n = (int)e.Value; if (n > mGlobal.WorkorderNumberStartSeed)//case 780 { mGlobal.WorkorderNumberStartSeed = (int)e.Value; } } break; case "PurchaseOrderStartSeed": { int n = (int)e.Value; if (n > mGlobal.PurchaseOrderStartSeed)//case 780 { mGlobal.PurchaseOrderStartSeed = (int)e.Value; } } break; case "QuoteNumberStartSeed": { int n = (int)e.Value; if (n > mGlobal.QuoteNumberStartSeed)//case 780 { mGlobal.QuoteNumberStartSeed = (int)e.Value; } } break; case "InventoryAdjustmentStartSeed": { int n = (int)e.Value; if (n > mGlobal.InventoryAdjustmentStartSeed)//case 780 { mGlobal.InventoryAdjustmentStartSeed = (int)e.Value; } } break; case "WorkorderSummaryTemplate": { mGlobal.WorkorderSummaryTemplate = (string)e.Value; } break; case "UseInventory": { mGlobal.UseInventory = (bool)e.Value; } break; case "MainGridAutoRefresh": { mGlobal.MainGridAutoRefresh = (bool)e.Value; } break;//case 1487 case "CJKIndex": { mGlobal.CJKIndex = (bool)e.Value; } break; case "DefaultUnitNameDisplayFormat": { mGlobal.DefaultUnitNameDisplayFormat = (UnitNameDisplayFormats)e.Value; } break; case "DefaultScheduleableUserNameDisplayFormat": { mGlobal.DefaultScheduleableUserNameDisplayFormat = (ScheduleableUserNameDisplayFormats)e.Value; } break; case "DefaultPartDisplayFormat": { mGlobal.DefaultPartDisplayFormat = (PartDisplayFormats)e.Value; } break; case "WorkorderCloseByAge": { mGlobal.WorkorderCloseByAge = (int)e.Value; } break; case "UseNotification": { mGlobal.UseNotification = (bool)e.Value; } break; case "NotifySMTPHost": { mGlobal.NotifySMTPHost = (string)e.Value; } break; case "NotifySMTPAccount": { mGlobal.NotifySMTPAccount = (string)e.Value; } break; case "NotifySMTPPassword": { mGlobal.NotifySMTPPassword = (string)e.Value; } break; case "NotifySMTPFrom": { mGlobal.NotifySMTPFrom = (string)e.Value; } break; //case 1136 case "NotifySMTPEncryptionMethod": { mGlobal.NotifySMTPEncryptionMethod = (string)e.Value; } break; //case 1382 case "SMTPRetry": { mGlobal.SMTPRetry = (bool)e.Value; } break; case "CoordinateStyle": { mGlobal.CoordinateStyle = (CoordinateTypes)e.Value; } break; case "DefaultLongitude": { mGlobal.DefaultLongitude = (LongitudeHemisphere)e.Value; } break; case "DefaultLatitude": { mGlobal.DefaultLatitude = (LatitudeHemisphere)e.Value; } break; case "DefaultClosedWorkorderStatus": { mGlobal.WorkorderClosedStatus = (Guid)e.Value; } break; case "MaxFileSizeMB": { mGlobal.MaxFileSizeMB = (int)e.Value; } break;//case 1839 (was missing completely) case "LaborSchedUserDfltTimeSpan": { mGlobal.LaborSchedUserDfltTimeSpan = (int)e.Value; } break;//case 816 case "TravelDfltTimeSpan": { mGlobal.TravelDfltTimeSpan = (int)e.Value; } break;//case 816 case "SchedUserNonTodayStartTime": { string s = (string)e.Value; if (string.IsNullOrWhiteSpace(s)) mGlobal.SchedUserNonTodayStartTime = ""; else mGlobal.SchedUserNonTodayStartTime = s; } break;//case 1392 case "SignatureTitle": { mGlobal.SignatureTitle = (string)e.Value; } break;//case 1346 case "SignatureHeader": { mGlobal.SignatureHeader = (string)e.Value; } break;//case 1346 case "SignatureFooter": { mGlobal.SignatureFooter = (string)e.Value; } break;//case 1346 } } #endregion #region Toolbar menu items /// /// Respond to a click on a toolbar menu item /// /// /// private void tbManager_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e) { //case 1039 //if(log.IsDebugEnabled) //case 1039 //log.Debug("ToolClick: "+e.Tool.Key); switch (e.Tool.Key) { case "LT:UI.Command.RecordHistory": // ButtonTool RecordHistoryForm RH = new RecordHistoryForm(mGlobal.Creator, mGlobal.Modifier, mGlobal.Created, mGlobal.Modified); RH.ShowDialog(); RH.Dispose(); break; case "LT:UI.Command.Save": // ButtonTool RecordUpdate(RecordActionType.SaveOnly); break; case "LT:UI.Command.Cancel": // ButtonTool this.mGlobal.CancelEdit(); break; case "LT:UI.Toolbar.Refresh": // case 1436 InitializePropertyGrid(); break; } } #endregion Toolbar menu items #region Form UI / Business object synchronization /// /// Synchronize the state of the UI to the BO's /// private void SyncUI() { tbManager.Tools["LT:UI.Command.Save"].SharedProps.Enabled = mGlobal.IsSavable; tbManager.Tools["LT:UI.Command.Cancel"].SharedProps.Enabled = mGlobal.IsSavable; //Read only full address boxes //edPostalAddress.Text=mGlobal.MailToAddress.FullAddress; //edPhysicalAddress.Text=mGlobal.GoToAddress.FullAddress; } /// /// When the application enters an idle state /// update the UI to reflect changs in BO status /// (required because grids don't tell the UI to update when they are /// bound to a business object and are edited) /// /// /// private void Application_Idle(object sender, EventArgs e) { SyncUI(); } /// /// Adapt UI to accomodate users security access level /// by default form is set with full rights in mind /// so this code just needs to restrict them as required /// private void RestrictUI() { //case 1039 //if(log.IsDebugEnabled) //case 1039 //log.Debug("RestrictUI: " + ((SecurityLevelTypes)AyaBizUtils.Right("Object.Global")).ToString()); bool ReadOnly = AyaBizUtils.Right("Object.Global") < (int)SecurityLevelTypes.ReadWrite; tbManager.Tools["LT:UI.Command.Save"].SharedProps.Visible = !ReadOnly; this.pGrid.Enabled = !ReadOnly; } #endregion #region Business object editing / adding / deletion related code private Global mGlobal; /// /// Global record to display /// set by caller /// public Global GlobalSettingToEdit { get { return mGlobal; } set { mGlobal = value; mGlobal.BeginEdit(); } } //Used to signal to main form that there are changes //which could affect it if true private bool mbChangesMade = false; public bool ChangesMade { get { return mbChangesMade; } } /// /// Update record and quit if requested /// /// /// True if handled, false if not handled private bool RecordUpdate(RecordActionType SaveType) { //case 1039 //if(log.IsDebugEnabled) //case 1039 //log.Debug("SaveHandler(Action="+SaveType.ToString()+")"); //switch the focus to a non-editable control //so that any changes in the current editable control //will get updated before attempting to save //btnAddress.Focus(); switch (SaveType) { case RecordActionType.SaveOnly: if (mGlobal.IsSavable) { while (mGlobal.IsEditing) mGlobal.ApplyEdit(); mGlobal = (Global)mGlobal.Save(); //DataBind(); mbChangesMade = true; return true; } return true; case RecordActionType.PromptToSave: //Prompt to save and save if //required if (mGlobal.IsDirty) { DialogResult dr = Util.PromptForSave(); if (dr == DialogResult.Cancel) { //Cancel return false; } if (dr == DialogResult.Yes) { //Save before exit if (mGlobal.IsSavable) { while (mGlobal.IsEditing) mGlobal.ApplyEdit(); mGlobal.Save(); mbChangesMade = true; return true; } if (mGlobal.IsDirty)//dirty and unsaveable due to broken rules { if (Util.PromptForBrokenRulesCancelSave() == DialogResult.Yes) { return true; } else return false; } } } return true; } return false; } #endregion #region PropertyBag /// /// Represents a single property in a PropertySpec. /// public class PropertySpec { private Attribute[] attributes; private string category; private object defaultValue; private string description; private string editor; private string name; private string type; private string typeConverter; private string key; /// /// Initializes a new instance of the PropertySpec class. /// /// The name of the property displayed in the property grid. /// The fully qualified name of the type of the property. public PropertySpec(string key, string name, string type) : this(key, name, type, null, null, null) { } /// /// Initializes a new instance of the PropertySpec class. /// /// The name of the property displayed in the property grid. /// A Type that represents the type of the property. public PropertySpec(string key, string name, Type type) : this(key, name, type.AssemblyQualifiedName, null, null, null) { } /// /// Initializes a new instance of the PropertySpec class. /// /// The name of the property displayed in the property grid. /// The fully qualified name of the type of the property. /// The category under which the property is displayed in the /// property grid. public PropertySpec(string key, string name, string type, string category) : this(key, name, type, category, null, null) { } /// /// Initializes a new instance of the PropertySpec class. /// /// The name of the property displayed in the property grid. /// A Type that represents the type of the property. /// public PropertySpec(string key, string name, Type type, string category) : this(key, name, type.AssemblyQualifiedName, category, null, null) { } /// /// Initializes a new instance of the PropertySpec class. /// /// The name of the property displayed in the property grid. /// The fully qualified name of the type of the property. /// The category under which the property is displayed in the /// property grid. /// A string that is displayed in the help area of the /// property grid. public PropertySpec(string key, string name, string type, string category, string description) : this(key, name, type, category, description, null) { } /// /// Initializes a new instance of the PropertySpec class. /// /// The name of the property displayed in the property grid. /// A Type that represents the type of the property. /// The category under which the property is displayed in the /// property grid. /// A string that is displayed in the help area of the /// property grid. public PropertySpec(string name, Type type, string category, string description) : this(name, type.AssemblyQualifiedName, category, description, null) { } /// /// Initializes a new instance of the PropertySpec class. /// /// The name of the property displayed in the property grid. /// The fully qualified name of the type of the property. /// The category under which the property is displayed in the /// property grid. /// A string that is displayed in the help area of the /// property grid. /// The default value of the property, or null if there is /// no default value. public PropertySpec(string key, string name, string type, string category, string description, object defaultValue) { this.key = key; this.name = name; this.type = type; this.category = category; this.description = description; this.defaultValue = defaultValue; this.attributes = null; } /// /// Initializes a new instance of the PropertySpec class. /// /// The name of the property displayed in the property grid. /// A Type that represents the type of the property. /// The category under which the property is displayed in the /// property grid. /// A string that is displayed in the help area of the /// property grid. /// The default value of the property, or null if there is /// no default value. public PropertySpec(string key, string name, Type type, string category, string description, object defaultValue) : this(key, name, type.AssemblyQualifiedName, category, description, defaultValue) { } // /// // /// Initializes a new instance of the PropertySpec class. // /// // /// The name of the property displayed in the property grid. // /// The fully qualified name of the type of the property. // /// The category under which the property is displayed in the // /// property grid. // /// A string that is displayed in the help area of the // /// property grid. // /// The default value of the property, or null if there is // /// no default value. // /// The fully qualified name of the type of the editor for this // /// property. This type must derive from UITypeEditor. // /// The fully qualified name of the type of the type // /// converter for this property. This type must derive from TypeConverter. // public PropertySpec(string key,string name, string type, string category, string description, object defaultValue, // string editor, string typeConverter) : this(key, name, type, category, description, defaultValue) // { // this.editor = editor; // this.typeConverter = typeConverter; // } // // /// // /// Initializes a new instance of the PropertySpec class. // /// // /// The name of the property displayed in the property grid. // /// A Type that represents the type of the property. // /// The category under which the property is displayed in the // /// property grid. // /// A string that is displayed in the help area of the // /// property grid. // /// The default value of the property, or null if there is // /// no default value. // /// The fully qualified name of the type of the editor for this // /// property. This type must derive from UITypeEditor. // /// The fully qualified name of the type of the type // /// converter for this property. This type must derive from TypeConverter. // public PropertySpec(string key,string name, Type type, string category, string description, object defaultValue, // string editor, string typeConverter) : // this(key, name, type.AssemblyQualifiedName, category, description, defaultValue, editor, typeConverter) { } // /// // /// Initializes a new instance of the PropertySpec class. // /// // /// The name of the property displayed in the property grid. // /// The fully qualified name of the type of the property. // /// The category under which the property is displayed in the // /// property grid. // /// A string that is displayed in the help area of the // /// property grid. // /// The default value of the property, or null if there is // /// no default value. // /// The Type that represents the type of the editor for this // /// property. This type must derive from UITypeEditor. // /// The fully qualified name of the type of the type // /// converter for this property. This type must derive from TypeConverter. // public PropertySpec(string key,string name, string type, string category, string description, object defaultValue, // Type editor, string typeConverter) : // this(key, name, type, category, description, defaultValue, editor.AssemblyQualifiedName, // typeConverter) { } // /// // /// Initializes a new instance of the PropertySpec class. // /// // /// The name of the property displayed in the property grid. // /// A Type that represents the type of the property. // /// The category under which the property is displayed in the // /// property grid. // /// A string that is displayed in the help area of the // /// property grid. // /// The default value of the property, or null if there is // /// no default value. // /// The Type that represents the type of the editor for this // /// property. This type must derive from UITypeEditor. // /// The fully qualified name of the type of the type // /// converter for this property. This type must derive from TypeConverter. // public PropertySpec(string key,string name, Type type, string category, string description, object defaultValue, // Type editor, string typeConverter) : // this(key, name, type.AssemblyQualifiedName, category, description, defaultValue, // editor.AssemblyQualifiedName, typeConverter) { } // /// // /// Initializes a new instance of the PropertySpec class. // /// // /// The name of the property displayed in the property grid. // /// The fully qualified name of the type of the property. // /// The category under which the property is displayed in the // /// property grid. // /// A string that is displayed in the help area of the // /// property grid. // /// The default value of the property, or null if there is // /// no default value. // /// The fully qualified name of the type of the editor for this // /// property. This type must derive from UITypeEditor. // /// The Type that represents the type of the type // /// converter for this property. This type must derive from TypeConverter. // public PropertySpec(string key,string name, string type, string category, string description, object defaultValue, // string editor, Type typeConverter) : // this(key, name, type, category, description, defaultValue, editor, typeConverter.AssemblyQualifiedName) { } // // /// // /// Initializes a new instance of the PropertySpec class. // /// // /// The name of the property displayed in the property grid. // /// A Type that represents the type of the property. // /// The category under which the property is displayed in the // /// property grid. // /// A string that is displayed in the help area of the // /// property grid. // /// The default value of the property, or null if there is // /// no default value. // /// The fully qualified name of the type of the editor for this // /// property. This type must derive from UITypeEditor. // /// The Type that represents the type of the type // /// converter for this property. This type must derive from TypeConverter. // public PropertySpec(string key, string name, Type type, string category, string description, object defaultValue, // string editor, Type typeConverter) : // this(key, name, type.AssemblyQualifiedName, category, description, defaultValue, editor, // typeConverter.AssemblyQualifiedName) { } // /// // /// Initializes a new instance of the PropertySpec class. // /// // /// The name of the property displayed in the property grid. // /// The fully qualified name of the type of the property. // /// The category under which the property is displayed in the // /// property grid. // /// A string that is displayed in the help area of the // /// property grid. // /// The default value of the property, or null if there is // /// no default value. // /// The Type that represents the type of the editor for this // /// property. This type must derive from UITypeEditor. // /// The Type that represents the type of the type // /// converter for this property. This type must derive from TypeConverter. // public PropertySpec(string key, string name, string type, string category, string description, object defaultValue, // Type editor, Type typeConverter) : // this(key, name, type, category, description, defaultValue, editor.AssemblyQualifiedName, // typeConverter.AssemblyQualifiedName) { } /// /// Initializes a new instance of the PropertySpec class. /// /// The name of the property displayed in the property grid. /// A Type that represents the type of the property. /// The category under which the property is displayed in the /// property grid. /// A string that is displayed in the help area of the /// property grid. /// The default value of the property, or null if there is /// no default value. /// The Type that represents the type of the editor for this /// property. This type must derive from UITypeEditor. /// The Type that represents the type of the type /// converter for this property. This type must derive from TypeConverter. public PropertySpec(string key, string name, Type type, string category, string description, object defaultValue, Type editor, Type typeConverter) { this.key = key; this.name = name; this.type = type.AssemblyQualifiedName; this.category = category; this.description = description; this.defaultValue = defaultValue; this.attributes = null; if (editor != null) this.editor = editor.AssemblyQualifiedName; if (typeConverter != null) this.typeConverter = typeConverter.AssemblyQualifiedName; } /// /// Gets or sets a collection of additional Attributes for this property. This can /// be used to specify attributes beyond those supported intrinsically by the /// PropertySpec class, such as ReadOnly and Browsable. /// public Attribute[] Attributes { get { return attributes; } set { attributes = value; } } /// /// Gets or sets the key of this property. /// public string Key { get { return key; } set { key = value; } } /// /// Gets or sets the category name of this property. /// public string Category { get { return category; } set { category = value; } } /// /// Gets or sets the fully qualified name of the type converter /// type for this property. /// public string ConverterTypeName { get { return typeConverter; } set { typeConverter = value; } } /// /// Gets or sets the default value of this property. /// public object DefaultValue { get { return defaultValue; } set { defaultValue = value; } } /// /// Gets or sets the help text description of this property. /// public string Description { get { return description; } set { description = value; } } /// /// Gets or sets the fully qualified name of the editor type for /// this property. /// public string EditorTypeName { get { return editor; } set { editor = value; } } /// /// Gets or sets the name of this property. /// public string Name { get { return name; } set { name = value; } } /// /// Gets or sets the fully qualfied name of the type of this /// property. /// public string TypeName { get { return type; } set { type = value; } } } /// /// Provides data for the GetValue and SetValue events of the PropertyBag class. /// public class PropertySpecEventArgs : EventArgs { private PropertySpec property; private object val; /// /// Initializes a new instance of the PropertySpecEventArgs class. /// /// The PropertySpec that represents the property whose /// value is being requested or set. /// The current value of the property. public PropertySpecEventArgs(PropertySpec property, object val) { this.property = property; this.val = val; } /// /// Gets the PropertySpec that represents the property whose value is being /// requested or set. /// public PropertySpec Property { get { return property; } } /// /// Gets or sets the current value of the property. /// public object Value { get { return val; } set { val = value; } } } /// /// Represents the method that will handle the GetValue and SetValue events of the /// PropertyBag class. /// public delegate void PropertySpecEventHandler(object sender, PropertySpecEventArgs e); /// /// Represents a collection of custom properties that can be selected into a /// PropertyGrid to provide functionality beyond that of the simple reflection /// normally used to query an object's properties. /// public class PropertyBag : ICustomTypeDescriptor { #region PropertySpecCollection class definition /// /// Encapsulates a collection of PropertySpec objects. /// [Serializable] public class PropertySpecCollection : IList { private ArrayList innerArray; /// /// Initializes a new instance of the PropertySpecCollection class. /// public PropertySpecCollection() { innerArray = new ArrayList(); } /// /// Gets the number of elements in the PropertySpecCollection. /// /// /// The number of elements contained in the PropertySpecCollection. /// public int Count { get { return innerArray.Count; } } /// /// Gets a value indicating whether the PropertySpecCollection has a fixed size. /// /// /// true if the PropertySpecCollection has a fixed size; otherwise, false. /// public bool IsFixedSize { get { return false; } } /// /// Gets a value indicating whether the PropertySpecCollection is read-only. /// public bool IsReadOnly { get { return false; } } /// /// Gets a value indicating whether access to the collection is synchronized (thread-safe). /// /// /// true if access to the PropertySpecCollection is synchronized (thread-safe); otherwise, false. /// public bool IsSynchronized { get { return false; } } /// /// Gets an object that can be used to synchronize access to the collection. /// /// /// An object that can be used to synchronize access to the collection. /// object ICollection.SyncRoot { get { return null; } } /// /// Gets or sets the element at the specified index. /// In C#, this property is the indexer for the PropertySpecCollection class. /// /// The zero-based index of the element to get or set. /// /// The element at the specified index. /// public PropertySpec this[int index] { get { return (PropertySpec)innerArray[index]; } set { innerArray[index] = value; } } /// /// Adds a PropertySpec to the end of the PropertySpecCollection. /// /// The PropertySpec to be added to the end of the PropertySpecCollection. /// The PropertySpecCollection index at which the value has been added. public int Add(PropertySpec value) { int index = innerArray.Add(value); return index; } /// /// Adds the elements of an array of PropertySpec objects to the end of the PropertySpecCollection. /// /// The PropertySpec array whose elements should be added to the end of the /// PropertySpecCollection. public void AddRange(PropertySpec[] array) { innerArray.AddRange(array); } /// /// Removes all elements from the PropertySpecCollection. /// public void Clear() { innerArray.Clear(); } /// /// Determines whether a PropertySpec is in the PropertySpecCollection. /// /// The PropertySpec to locate in the PropertySpecCollection. The element to locate /// can be a null reference (Nothing in Visual Basic). /// true if item is found in the PropertySpecCollection; otherwise, false. public bool Contains(PropertySpec item) { return innerArray.Contains(item); } /// /// Determines whether a PropertySpec with the specified name is in the PropertySpecCollection. /// /// The name of the PropertySpec to locate in the PropertySpecCollection. /// true if item is found in the PropertySpecCollection; otherwise, false. public bool Contains(string name) { foreach (PropertySpec spec in innerArray) if (spec.Name == name) return true; return false; } /// /// Copies the entire PropertySpecCollection to a compatible one-dimensional Array, starting at the /// beginning of the target array. /// /// The one-dimensional Array that is the destination of the elements copied /// from PropertySpecCollection. The Array must have zero-based indexing. public void CopyTo(PropertySpec[] array) { innerArray.CopyTo(array); } /// /// Copies the PropertySpecCollection or a portion of it to a one-dimensional array. /// /// The one-dimensional Array that is the destination of the elements copied /// from the collection. /// The zero-based index in array at which copying begins. public void CopyTo(PropertySpec[] array, int index) { innerArray.CopyTo(array, index); } /// /// Returns an enumerator that can iterate through the PropertySpecCollection. /// /// An IEnumerator for the entire PropertySpecCollection. public IEnumerator GetEnumerator() { return innerArray.GetEnumerator(); } /// /// Searches for the specified PropertySpec and returns the zero-based index of the first /// occurrence within the entire PropertySpecCollection. /// /// The PropertySpec to locate in the PropertySpecCollection. /// The zero-based index of the first occurrence of value within the entire PropertySpecCollection, /// if found; otherwise, -1. public int IndexOf(PropertySpec value) { return innerArray.IndexOf(value); } /// /// Searches for the PropertySpec with the specified name and returns the zero-based index of /// the first occurrence within the entire PropertySpecCollection. /// /// The name of the PropertySpec to locate in the PropertySpecCollection. /// The zero-based index of the first occurrence of value within the entire PropertySpecCollection, /// if found; otherwise, -1. public int IndexOf(string name) { int i = 0; foreach (PropertySpec spec in innerArray) { if (spec.Name == name) return i; i++; } return -1; } /// /// Inserts a PropertySpec object into the PropertySpecCollection at the specified index. /// /// The zero-based index at which value should be inserted. /// The PropertySpec to insert. public void Insert(int index, PropertySpec value) { innerArray.Insert(index, value); } /// /// Removes the first occurrence of a specific object from the PropertySpecCollection. /// /// The PropertySpec to remove from the PropertySpecCollection. public void Remove(PropertySpec obj) { innerArray.Remove(obj); } /// /// Removes the property with the specified name from the PropertySpecCollection. /// /// The name of the PropertySpec to remove from the PropertySpecCollection. public void Remove(string name) { int index = IndexOf(name); RemoveAt(index); } /// /// Removes the object at the specified index of the PropertySpecCollection. /// /// The zero-based index of the element to remove. public void RemoveAt(int index) { innerArray.RemoveAt(index); } /// /// Copies the elements of the PropertySpecCollection to a new PropertySpec array. /// /// A PropertySpec array containing copies of the elements of the PropertySpecCollection. public PropertySpec[] ToArray() { return (PropertySpec[])innerArray.ToArray(typeof(PropertySpec)); } #region Explicit interface implementations for ICollection and IList /// /// This member supports the .NET Framework infrastructure and is not intended to be used directly from your code. /// void ICollection.CopyTo(Array array, int index) { CopyTo((PropertySpec[])array, index); } /// /// This member supports the .NET Framework infrastructure and is not intended to be used directly from your code. /// int IList.Add(object value) { return Add((PropertySpec)value); } /// /// This member supports the .NET Framework infrastructure and is not intended to be used directly from your code. /// bool IList.Contains(object obj) { return Contains((PropertySpec)obj); } /// /// This member supports the .NET Framework infrastructure and is not intended to be used directly from your code. /// object IList.this[int index] { get { return ((PropertySpecCollection)this)[index]; } set { ((PropertySpecCollection)this)[index] = (PropertySpec)value; } } /// /// This member supports the .NET Framework infrastructure and is not intended to be used directly from your code. /// int IList.IndexOf(object obj) { return IndexOf((PropertySpec)obj); } /// /// This member supports the .NET Framework infrastructure and is not intended to be used directly from your code. /// void IList.Insert(int index, object value) { Insert(index, (PropertySpec)value); } /// /// This member supports the .NET Framework infrastructure and is not intended to be used directly from your code. /// void IList.Remove(object value) { Remove((PropertySpec)value); } #endregion } #endregion #region PropertySpecDescriptor class definition private class PropertySpecDescriptor : PropertyDescriptor { private PropertyBag bag; private PropertySpec item; public PropertySpecDescriptor(PropertySpec item, PropertyBag bag, string name, Attribute[] attrs) : base(name, attrs) { this.bag = bag; this.item = item; } public override Type ComponentType { get { return item.GetType(); } } public override bool IsReadOnly { get { return (Attributes.Matches(ReadOnlyAttribute.Yes)); } } public override Type PropertyType { get { return Type.GetType(item.TypeName); } } public override bool CanResetValue(object component) { if (item.DefaultValue == null) return false; else return !this.GetValue(component).Equals(item.DefaultValue); } public override object GetValue(object component) { // Have the property bag raise an event to get the current value // of the property. PropertySpecEventArgs e = new PropertySpecEventArgs(item, null); bag.OnGetValue(e); return e.Value; } public override void ResetValue(object component) { SetValue(component, item.DefaultValue); } public override void SetValue(object component, object value) { // Have the property bag raise an event to set the current value // of the property. PropertySpecEventArgs e = new PropertySpecEventArgs(item, value); bag.OnSetValue(e); } public override bool ShouldSerializeValue(object component) { object val = this.GetValue(component); if (item.DefaultValue == null && val == null) return false; else return !val.Equals(item.DefaultValue); } } #endregion private string defaultProperty; private PropertySpecCollection properties; /// /// Initializes a new instance of the PropertyBag class. /// public PropertyBag() { defaultProperty = null; properties = new PropertySpecCollection(); } /// /// Gets or sets the name of the default property in the collection. /// public string DefaultProperty { get { return defaultProperty; } set { defaultProperty = value; } } /// /// Gets the collection of properties contained within this PropertyBag. /// public PropertySpecCollection Properties { get { return properties; } } /// /// Occurs when a PropertyGrid requests the value of a property. /// public event PropertySpecEventHandler GetValue; /// /// Occurs when the user changes the value of a property in a PropertyGrid. /// public event PropertySpecEventHandler SetValue; /// /// Raises the GetValue event. /// /// A PropertySpecEventArgs that contains the event data. protected virtual void OnGetValue(PropertySpecEventArgs e) { if (GetValue != null) GetValue(this, e); } /// /// Raises the SetValue event. /// /// A PropertySpecEventArgs that contains the event data. protected virtual void OnSetValue(PropertySpecEventArgs e) { if (SetValue != null) SetValue(this, e); } #region ICustomTypeDescriptor explicit interface definitions // Most of the functions required by the ICustomTypeDescriptor are // merely pssed on to the default TypeDescriptor for this type, // which will do something appropriate. The exceptions are noted // below. AttributeCollection ICustomTypeDescriptor.GetAttributes() { return TypeDescriptor.GetAttributes(this, true); } string ICustomTypeDescriptor.GetClassName() { return TypeDescriptor.GetClassName(this, true); } string ICustomTypeDescriptor.GetComponentName() { return TypeDescriptor.GetComponentName(this, true); } TypeConverter ICustomTypeDescriptor.GetConverter() { return TypeDescriptor.GetConverter(this, true); } EventDescriptor ICustomTypeDescriptor.GetDefaultEvent() { return TypeDescriptor.GetDefaultEvent(this, true); } PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty() { // This function searches the property list for the property // with the same name as the DefaultProperty specified, and // returns a property descriptor for it. If no property is // found that matches DefaultProperty, a null reference is // returned instead. PropertySpec propertySpec = null; if (defaultProperty != null) { int index = properties.IndexOf(defaultProperty); propertySpec = properties[index]; } if (propertySpec != null) return new PropertySpecDescriptor(propertySpec, this, propertySpec.Name, null); else return null; } object ICustomTypeDescriptor.GetEditor(Type editorBaseType) { return TypeDescriptor.GetEditor(this, editorBaseType, true); } EventDescriptorCollection ICustomTypeDescriptor.GetEvents() { return TypeDescriptor.GetEvents(this, true); } EventDescriptorCollection ICustomTypeDescriptor.GetEvents(Attribute[] attributes) { return TypeDescriptor.GetEvents(this, attributes, true); } PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties() { return ((ICustomTypeDescriptor)this).GetProperties(new Attribute[0]); } PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes) { // Rather than passing this function on to the default TypeDescriptor, // which would return the actual properties of PropertyBag, I construct // a list here that contains property descriptors for the elements of the // Properties list in the bag. ArrayList props = new ArrayList(); foreach (PropertySpec property in properties) { ArrayList attrs = new ArrayList(); // If a category, description, editor, or type converter are specified // in the PropertySpec, create attributes to define that relationship. if (property.Category != null) attrs.Add(new CategoryAttribute(property.Category)); if (property.Description != null) attrs.Add(new DescriptionAttribute(property.Description)); if (property.EditorTypeName != null) attrs.Add(new EditorAttribute(property.EditorTypeName, typeof(System.Drawing.Design.UITypeEditor))); if (property.ConverterTypeName != null) attrs.Add(new TypeConverterAttribute(property.ConverterTypeName)); // Additionally, append the custom attributes associated with the // PropertySpec, if any. if (property.Attributes != null) attrs.AddRange(property.Attributes); Attribute[] attrArray = (Attribute[])attrs.ToArray(typeof(Attribute)); // Create a new property descriptor for the property item, and add // it to the list. PropertySpecDescriptor pd = new PropertySpecDescriptor(property, this, property.Name, attrArray); props.Add(pd); } // Convert the list of PropertyDescriptors to a collection that the // ICustomTypeDescriptor can use, and return it. PropertyDescriptor[] propArray = (PropertyDescriptor[])props.ToArray( typeof(PropertyDescriptor)); return new PropertyDescriptorCollection(propArray); } object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor pd) { return this; } #endregion } /// /// An extension of PropertyBag that manages a table of property values, in /// addition to firing events when property values are requested or set. /// public class PropertyTable : PropertyBag { private Hashtable propValues; /// /// Initializes a new instance of the PropertyTable class. /// public PropertyTable() { propValues = new Hashtable(); } /// /// Gets or sets the value of the property with the specified name. ///

In C#, this property is the indexer of the PropertyTable class.

///
public object this[string key] { get { return propValues[key]; } set { propValues[key] = value; } } /// /// This member overrides PropertyBag.OnGetValue. /// protected override void OnGetValue(PropertySpecEventArgs e) { e.Value = propValues[e.Property.Name]; base.OnGetValue(e); } /// /// This member overrides PropertyBag.OnSetValue. /// protected override void OnSetValue(PropertySpecEventArgs e) { propValues[e.Property.Name] = e.Value; base.OnSetValue(e); } } #endregion } }