private void OnMenuClick(object sender, System.EventArgs e) { //Event handler for menu selection Issue issue = null; try { ToolStripDropDownItem menu = (ToolStripDropDownItem)sender; switch (menu.Text) { case MNU_NEW: issue = CRGFactory.GetIssue(0); dlgIssue dlg = new dlgIssue(issue); dlg.Font = this.Font; if (dlg.ShowDialog() == DialogResult.OK) { this.Cursor = Cursors.WaitCursor; if (issue.Save()) { for (int i = 0; i < this.grdIssues.Rows.Count; i++) { int id = Convert.ToInt32(this.grdIssues.Rows[i].Cells["ID"].Value); if (id == issue.ID) { this.grdIssues.Rows[i].Selected = true; this.grdIssues.DisplayLayout.Bands[0].Columns["LastActionCreated"].SortIndicator = SortIndicator.Descending; OnGridSelectionChanged(this.grdIssues, null); break; } } } } break; case MNU_OPEN: break; case MNU_SAVE: break; case MNU_SAVEAS: SaveFileDialog dlgSave = new SaveFileDialog(); dlgSave.AddExtension = true; dlgSave.Filter = "Export Files (*.xml) | *.xml | Excel Files (*.xls) | *.xls"; dlgSave.FilterIndex = 0; dlgSave.Title = "Save Issues As..."; dlgSave.FileName = ""; dlgSave.OverwritePrompt = true; if (dlgSave.ShowDialog(this) == DialogResult.OK) { this.Cursor = Cursors.WaitCursor; Application.DoEvents(); if (dlgSave.FileName.EndsWith("xls")) { new Argix.ExcelFormat().Transform(this.mIssues, dlgSave.FileName); } else { this.mIssues.WriteXml(dlgSave.FileName, XmlWriteMode.WriteSchema); } } break; case MNU_SETUP: UltraGridPrinter.PageSettings(); break; case MNU_PRINT: UltraGridPrinter.Print(this.grdIssues, this.grdIssues.Text, true); break; case MNU_PREVIEW: UltraGridPrinter.PrintPreview(this.grdIssues, this.grdIssues.Text); break; case MNU_REFRESH: this.Cursor = Cursors.WaitCursor; this.mGridSvcIssues.CaptureState("ID"); switch (this.cboView.Text) { case "Search Results": break; case "Issue History": this.mIssueHistory.Clear(); this.mIssueHistory.Merge(CRGFactory.IssueHistory(this.mIssueH)); break; case "Draft Issues": break; default: DataSet ds = CRGFactory.GetIssues(); lock (this.mIssues) { this.mIssues.Clear(); this.mIssues.Merge(ds); } postIssueUpdates(); break; } this.mGridSvcIssues.RestoreState(); break; case MNU_REFRESHCACHE: EnterpriseFactory.RefreshCache(); CRGFactory.RefreshCache(); break; case MNU_AUTOREFRESHON: this.mnuCtxAutoRefreshOn.Checked = !this.mnuCtxAutoRefreshOn.Checked; if (this.mnuCtxAutoRefreshOn.Checked) { StartAuto(); } else { StopAuto(); } break; case MNU_CONTACTS: winContacts winC = new winContacts(); winC.Font = this.Font; winC.ShowDialog(); break; case MNU_PROPERTIES: break; } } catch (Exception ex) { reportError(ex); } finally { setUserServices(); this.Cursor = Cursors.Default; } }
public void OnFileAction(Office.IRibbonControl control) { //Event handler for view contacts clicked Outlook.Inspector insp = null; Outlook.MailItem m = null; Outlook.Attachments attachments = null; Issue issue = null; try { Tools.CustomTaskPane ctp = null; IssueSelector ie = null; Outlook.Inspector inspector = (Outlook.Inspector)control.Context; if (Globals.ThisAddIn.InspectorWrappers.ContainsKey(inspector)) { InspectorWrapper iw = Globals.ThisAddIn.InspectorWrappers[inspector]; ctp = iw.CustomTaskPane; if (ctp != null) { ie = (IssueSelector)ctp.Control; } } switch (control.Id) { case "btnNew": //Add the current outlook message as an issue action in a new issue //Show explorer if not visible ctp.Visible = true; //Get the current email item and any associated attachments insp = Globals.ThisAddIn.Application.ActiveInspector(); m = (Outlook.MailItem)insp.CurrentItem; attachments = m.Attachments; //Get a new issue; allow user interaction issue = CRGFactory.GetIssue(0); issue.Subject = m.Subject; issue.Actions.ActionTable[0].Comment = m.Body; if (new dlgIssue(issue).ShowDialog() == DialogResult.OK) { //Save (create) the new issue issue.Save(); if (ie != null) { ie.SelectedID = issue.ID; } } break; case "btnAdd": //Add the current outlook message as an issue action issue = ie != null ? ie.SelectedIssue : null; if (issue == null) { App.ReportError(new ApplicationException("Could not determine selected issue."), true, LogLevel.Error); } else { //Get the current email item and any associated attachments insp = Globals.ThisAddIn.Application.ActiveInspector(); m = (Outlook.MailItem)insp.CurrentItem; attachments = m.Attachments; //Get a new action and add attachments Issue.Action action = issue.Item(0); action.Comment = m.Body; foreach (Outlook.Attachment a in attachments) { Issue.Attachment attachment = action.Item(0); attachment.Filename = CRGFactory.TempFolder + a.FileName; action.Add(attachment); } //Allow user interaction if (new dlgAction(action).ShowDialog() == DialogResult.OK) { //Save selected attachments to TEMP dir foreach (Outlook.Attachment a in attachments) { try { if (action.Item(CRGFactory.TempFolder + a.FileName) != null) { a.SaveAsFile(CRGFactory.TempFolder + a.FileName); } } catch (Exception ex) { App.ReportError(new ApplicationException("Unexpected error while saving mail attachments to temporary storage; continuing...", ex), true, LogLevel.Error); } } //Save the action issue.Add(action); ie.SelectedID = issue.ID; } } break; } } catch (ApplicationException ex) { throw ex; } catch (Exception ex) { App.ReportError(new ApplicationException("Unexpected error while handling File actions in the Issue Mgt ribbon extension.", ex), true, LogLevel.Error); } finally { this.mRibbonUI.Invalidate(); } }