///<summary>Sets up a button that can use data for a range of years.</summary> ///<typeparam name="TRow">The strongly-typed Singularity row that the feature uses. These rows are used to populate the years dropdown.</typeparam> ///<param name="button">The button that initiates the action.</param> ///<param name="yearGetter">A delegate that gets the year represented by a row. This is called to populate the years dropdown.</param> ///<param name="showForm">The method bound to the button.</param> ///<param name="defaultYear">The year used when clicking the button itself. This year will also be bolded in the dropdown. Defaults to the current year.</param> public static void SetupYearlyButton <TRow>(this BarButtonItem button, Func <TRow, int?> yearGetter, Action <int> showForm, int?defaultYear = null) where TRow : Row { if (button == null) { throw new ArgumentNullException("button"); } if (yearGetter == null) { throw new ArgumentNullException("yearGetter"); } if (showForm == null) { throw new ArgumentNullException("showForm"); } defaultYear = defaultYear ?? DateTime.Now.Year; var menu = new PopupMenu(button.Manager); button.Disposed += delegate { menu.Dispose(); }; if (button.DropDownSuperTip == null) { button.DropDownSuperTip = Utilities.CreateSuperTip(button.Caption, "Shows a " + button.Caption + " for a specific year"); } button.ButtonStyle = BarButtonStyle.DropDown; button.DropDownControl = menu; button.ItemClick += delegate { showForm(defaultYear.Value); }; menu.BeforePopup += delegate { foreach (var link in menu.ItemLinks.Cast <BarItemLink>().ToList()) //Collection will be modified { button.Manager.Items.Remove(link.Item); } menu.ItemLinks.Clear(); AppFramework.LoadTable <TRow>(); foreach (int dontUse in AppFramework.Table <TRow>().Rows .Select(yearGetter) .Where(y => y.HasValue) .Distinct() .OrderByDescending(y => y)) { int year = dontUse; //Force separate variable per closure var item = new BarButtonItem(button.Manager, year.ToString(CultureInfo.CurrentCulture)); item.ItemClick += delegate { showForm(year); }; if (year == defaultYear) { item.Appearance.Font = new Font(item.Appearance.GetFont(), FontStyle.Bold); } menu.AddItem(item); } }; }
protected static void CheckDesignTime(AppFramework instance) { if (Current != null) { return; } Current = instance; RegisterStandardSettings(); //Call CreateDataContext() first so that RegisterSettings() //can use additional columns created in CreateDataContext() instance.SyncContext = instance.CreateDataContext(); instance.RegisterSettings(); try { instance.SyncContext.ReadData(); } catch { instance.SyncContext = instance.CreateDataContext(); } //Ignore SQL errors at design time }
///<summary>Creates an AutoSaver that saves for the specified application.</summary> public AutoSaver(AppFramework app) { App = app; timer.Tick += Timer_Tick; }