private void btnAddItem_Click(object sender, EventArgs e) { Cursor = Cursors.Wait; try { var menuItem = (MenuItem)sender; var pairEntry = (ImageSourceListItem <Type>)menuItem.DataContext; EntryObjectInstanceAttribute entryAttribute = new EntryObjectInstanceAttribute(); var attributes = pairEntry.Value.GetCustomAttributes(typeof(EntryObjectInstanceAttribute), true); if (attributes.Length > 0) { entryAttribute = (EntryObjectInstanceAttribute)attributes[0]; } //if this type can be only once added then we need to check if we can add it if (entryAttribute.Instance == EntryObjectInstance.Single) { if (day.ContainsSpecifiedEntry(pairEntry.Value)) { BAMessageBox.ShowError(Strings.ErrorEntryObjectTypeAlreadyExists); return; } } var entry = day.AddEntry(pairEntry.Value); if (day.TrainingDate.IsFuture()) {//for entries in future set planned status entry.Status = EntryObjectStatus.Planned; } if (EntryObjectBuilder != null) { EntryObjectBuilder.EntryObjectCreated(entry); } try { createNewEntryControl(entry, true, null); SetModifiedFlag(); Cursor = Cursors.Arrow; } catch (TrainingIntegrationException ex) { day.RemoveEntry(entry); ExceptionHandler.Default.Process(ex, Strings.ErrorTrainingIntegrity, ErrorWindow.MessageBox); } catch (Exception ex) { day.RemoveEntry(entry); ExceptionHandler.Default.Process(ex, Strings.ErrorUnhandledException, ErrorWindow.EMailReport); } } finally { Cursor = Cursors.Arrow; } }
private void tsStrengthTraining_Click(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; try { ToolStripDropDownItem menuItem = (ToolStripDropDownItem)sender; KeyValuePair <Type, Type> pairEntry = (KeyValuePair <Type, Type>)menuItem.Tag; EntryObjectInstanceAttribute entryAttribute = new EntryObjectInstanceAttribute(); var attributes = pairEntry.Key.GetCustomAttributes(typeof(EntryObjectInstanceAttribute), true); if (attributes.Length > 0) { entryAttribute = (EntryObjectInstanceAttribute)attributes[0]; } //if this type can be only once added then we need to check if we can add it if (entryAttribute.Instance == EntryObjectInstance.Single) { if (day.ContainsSpecifiedEntry(pairEntry.Key)) { FMMessageBox.ShowError(ApplicationStrings.ErrorEntryObjectTypeAlreadyExists); return; } } var entry = day.CreateEntryObject(pairEntry.Key); try { createNewEntryControl(entry, true); day.AddEntry(entry); Cursor = Cursors.Default; } catch (TrainingIntegrationException ex) { ExceptionHandler.Default.Process(ex, ApplicationStrings.ErrorTrainingIntegrity, ErrorWindow.MessageBox); } catch (Exception ex) { ExceptionHandler.Default.Process(ex, ApplicationStrings.ErrorUnhandledException, ErrorWindow.EMailReport); } } finally { Cursor = Cursors.Default; } }