private void addButton_Click(object sender, EventArgs e) { try { SimpleListDialog listDialog = new SimpleListDialog(SourceObjectType); DialogResult res = listDialog.ShowDialog(); if (res == DialogResult.OK && listDialog.SelectedObjects != null && listDialog.SelectedObjects.Count > 0) { IList newObjects = listDialog.SelectedObjects; foreach (var newObject in newObjects) { bool oPresent = false; foreach (var o in listView.Objects) { if (o.Equals(newObject)) { oPresent = true; break; } } if (oPresent == false) { this.listView.AddObject(newObject); this.listView.EnsureModelVisible(newObject); } } } } catch (Exception ex) { Log.ShowError(ex); } }
protected void CreateFileMenuItems(ToolStripMenuItem menuItemFile) { ToolStripMenuItem menuItem = null; ToolStripMenuItem groupItem = null; groupItem = new ToolStripMenuItem(FrwCRUDRes.Close); menuItemFile.DropDownItems.Add(groupItem); menuItem = new ToolStripMenuItem(FrwCRUDRes.ActiveDocumentWindow); menuItem.Click += (s, em) => { try { CloseActiveDocument(); } catch (Exception ex) { Log.ShowError(ex); } }; groupItem.DropDownItems.Add(menuItem); menuItem = new ToolStripMenuItem(FrwCRUDRes.AllDocumentsExpectActive); menuItem.Click += (s, em) => { try { CloseAllContents(true, true); } catch (Exception ex) { Log.ShowError(ex); } }; groupItem.DropDownItems.Add(menuItem); menuItem = new ToolStripMenuItem(FrwCRUDRes.AllDocuments); menuItem.Click += (s, em) => { try { CloseAllContents(false, true); } catch (Exception ex) { Log.ShowError(ex); } }; groupItem.DropDownItems.Add(menuItem); menuItem = new ToolStripMenuItem(FrwCRUDRes.AllWindows); menuItem.Click += (s, em) => { try { CloseAllContents(false, false); } catch (Exception ex) { Log.ShowError(ex); } }; groupItem.DropDownItems.Add(menuItem); groupItem = new ToolStripMenuItem(FrwCRUDRes.WidgetSConfiguration); menuItemFile.DropDownItems.Add(groupItem); menuItem = new ToolStripMenuItem(FrwCRUDRes.LoadConfiguration); menuItem.Click += (s, em) => { SimpleListDialog listDialog = new SimpleListDialog(typeof(JDocPanelLayout)); DialogResult res = listDialog.ShowDialog(); if (res == DialogResult.OK && listDialog.SelectedObjects != null && listDialog.SelectedObjects.Count > 0) { IList layouts = listDialog.SelectedObjects; foreach (var layout in layouts) { //JDocPanelLayout layout = Dm.Instance.FindAll<JDocPanelLayout>().FirstOrDefault<JDocPanelLayout>(c => c.JDocPanelLayoutId == "1"); AppManager.Instance.LoadLayout((JDocPanelLayout)layout); break; } } }; groupItem.DropDownItems.Add(menuItem); menuItem = new ToolStripMenuItem(FrwCRUDRes.SaveConfiguration); menuItem.Click += (s, em) => { JDocPanelLayout layout = Dm.Instance.EmptyObject <JDocPanelLayout>(null); SimpleTextDialog dlg = new SimpleTextDialog(); if (dlg.ShowDialog() == DialogResult.OK && !string.IsNullOrEmpty(dlg.EditedText)) { layout.Name = dlg.EditedText; AppManager.Instance.SaveLayout(layout); Dm.Instance.SaveObject(layout); } }; groupItem.DropDownItems.Add(menuItem); menuItem = new ToolStripMenuItem(FrwCRUDRes.UpdateCurrentConfiguration); menuItem.Name = "UpdateCurrentConfiguration"; menuItem.Enabled = (AppManager.Instance.CurrentLayout != null); menuItem.Click += (s, em) => { AppManager.Instance.SaveLayout(AppManager.Instance.CurrentLayout); }; groupItem.DropDownOpening += (s, em) => { var mc = groupItem.DropDownItems["UpdateCurrentConfiguration"]; if (mc != null) { mc.Enabled = (AppManager.Instance.CurrentLayout != null); } }; groupItem.DropDownItems.Add(menuItem); CreateMainMenuItemForEntityType(groupItem, typeof(JDocPanelLayout)); menuItem = new ToolStripMenuItem(FrwCRUDRes.BaseMainAppForm_OpenNewContainerWindow); menuItem.Click += (s, em) => { Cursor cursor = Cursor.Current; try { Cursor.Current = Cursors.WaitCursor; BaseMainAppForm.CreateWindowNotClosable = false; Form newWindow = (Form)Activator.CreateInstance(this.GetType()); newWindow.Show(); } catch (Exception ex) { Log.ShowError(ex); } finally { Cursor.Current = cursor; } }; menuItemFile.DropDownItems.Add(menuItem); if (NotClosable && DocPanelIndex == 0) { menuItem = new ToolStripMenuItem(FrwCRUDRes.BaseMainAppForm_HideMainApplicationWindow);// menuItem.Click += (s, em) => { try { FrwConfig.Instance.SetPropertyValue(BaseApplicationContext.SETTING_showMainFormOnStartup, false); Hide(); } catch (Exception ex) { Log.ShowError(ex); } }; menuItemFile.DropDownItems.Add(menuItem); menuItem = new ToolStripMenuItem(FrwCRUDRes.CloseApplication); menuItem.Click += (s, em) => { try { AppManager.Instance.ExitApplication(); } catch (Exception ex) { Log.ShowError(ex); } }; menuItemFile.DropDownItems.Add(menuItem); } else { menuItemFile.DropDownItems.Add(menuItem); menuItem = new ToolStripMenuItem(DocPanelIndex == 0 ? FrwCRUDRes.CloseApplication : FrwCRUDRes.BaseMainAppForm_CloseContainerWindow); menuItem.Click += (s, em) => { try { Close(); } catch (Exception ex) { Log.ShowError(ex); } }; menuItemFile.DropDownItems.Add(menuItem); } }