///////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Opens existing or creates new form of FormBase subtype T in specified /// mode, optionally executing some action before the form is shown. /// </summary> /// internal T Open <T>(OpenMode mode = OpenMode.Browse, Action <T> actionBeforeOpen = null) where T : FormBase, new () { T form = null; MdiClient.IfValidateOk(() => { form = Find <T> (); // Reuse existing form i.e. don't allow multiple instances // if (form == null) { form = new T(); } // User can set e.g. common filter to filter records in delegate // if (form != null && actionBeforeOpen != null) { actionBeforeOpen(form); } // Open form finally // if (form != null) { form.OpenForm(mode); } }); return(form); }
///////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Displays the report box with a specified contents and caption. /// </summary> /// private void ShowReport(string caption, string report, bool modal = false) { MdiClient.IfValidateOk(() => { MyReportBox.ShowReport(caption, report, 700, this.Height - 50); }); }
///////////////////////////////////////////////////////////////////////////////////// #region [ Common Utilities ] /// <summary> /// Unload all MDI child forms (derived from FormBase). /// </summary> /// private void UnloadAllMdiChildForms() { MdiClient.IfValidateOk(() => { ExecuteFor <FormBase>(f => f.QuitForm()); }); }
///////////////////////////////////////////////////////////////////////////////////// #region [ Sudoku Puzzle - Method ] /// <summary> /// Creates new instance of the SudokuForm class and displays it. /// </summary> /// private void OpenSudoku() { MdiClient.IfValidateOk(() => { SudokuForm sudoku = new SudokuForm(); sudoku.MdiParent = this; sudoku.LoadAiEscargot(); sudoku.Show(); }); }
///////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Opens new form of FormBase subtype T in AddNew mode. /// </summary> /// private bool OpenAddNew <T> () where T : FormBase, new () { T form = null; MdiClient.IfValidateOk(() => { form = Find <T> (); // Open form if exists // if (form != null) { form.OpenForm(OpenMode.AddNew); } }); return(form != null); }
/// <summary> /// Opens existing (previously hidden) or creates new Sudoku puzzle form. /// </summary> /// private void OpenSudoku() { MdiClient.IfValidateOk(() => { if (sudokuForm == null) { sudokuForm = new SudokuForm() { Parent = this, FileName = "sudoku.txt", }; sudokuForm.LostFocus += (sender, e) => sudokuForm.Unload(); sudokuForm.Center(); sudokuForm.LoadAiEscargot(); } sudokuForm.Parent = this; }); }
///////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Initializes File menu item in the main menu. /// </summary> /// private void InitializeMenu_File() { Menu parent = this.Menu; MenuItem miFile = new MenuItem("&File"); SetToolTip(miFile, "Manage price list, company info and database files..."); parent.MenuItems.Add(miFile); //------------------------------------------------------------------------------- MenuItem miCompanyInfo = new MenuItem("&Company details...") { Shortcut = Shortcut.F4, }; SetToolTip(miCompanyInfo, "Manage Video Rental Outlet company information..."); miFile.MenuItems.Add(miCompanyInfo); miCompanyInfo.Click += delegate { Open <CompanyDetailsForm>(OpenMode.Browse); }; //------------------------------------------------------------------------------- InitializeMenu_PriceList(miFile); //------------------------------------------------------------------------------- miFile.MenuItems.Add(new MenuItem("-")); //------------------------------------------------------------------------------- InitializeMenu_Database(miFile); //------------------------------------------------------------------------------- InitializeMenu_Backup(miFile); //------------------------------------------------------------------------------- miFile.MenuItems.Add(new MenuItem("-")); //------------------------------------------------------------------------------- MenuItem miFileSave = new MenuItem("&Save") { Shortcut = Shortcut.CtrlS }; SetToolTip(miFileSave, "Save database"); miFile.MenuItems.Add(miFileSave); miFileSave.Click += delegate { MdiClient.IfValidateOk(() => { SaveDatabase(this.databaseFilename, "Saving Database", /*silent*/ true); }); }; //------------------------------------------------------------------------------- MenuItem miFileExit = new MenuItem("Save and E&xit") { Shortcut = Shortcut.AltF4 }; SetToolTip(miFileExit, "Save database and exit application ..."); miFile.MenuItems.Add(miFileExit); miFileExit.Click += delegate { MdiClient.IfValidateOk(() => { if (VideoStore.IsDirty) { SaveDatabase(this.databaseFilename, "Saving Database", /*silent*/ true); } Application.Exit(); }); }; }