예제 #1
0
        private void OnDragDrop(object sender, System.Windows.Forms.DragEventArgs e)
        {
            //Event handler for dropping onto the listview
            try {
                DataObject data = (DataObject)e.Data;
                if (data.GetDataPresent(DataFormats.FileDrop))
                {
                    //Local file
                    string[] names = (string[])data.GetData(DataFormats.FileDrop);
                    if (names.Length > 0)
                    {
                        //Save attachment
                        long             id         = Convert.ToInt64(this.lsvActions.SelectedItems[0].Name);
                        Issue.Action     action     = this.mIssue.Item(id);
                        Issue.Attachment attachment = action.Item(0);
                        attachment.Filename = names[0];
                        attachment.Save();
                    }
                }
                else if (data.GetDataPresent("FileGroupDescriptor"))
                {
                    //Outlook attachment
                    //Set the position within the current stream to the beginning of the file name
                    //return the file name in the fileName variable
                    System.IO.MemoryStream stream = (System.IO.MemoryStream)data.GetData("FileGroupDescriptor");
                    stream.Seek(76, System.IO.SeekOrigin.Begin);
                    byte[] fileName = new byte[256];
                    stream.Read(fileName, 0, 256);
                    System.Text.Encoding encoding = System.Text.Encoding.ASCII;
                    string name = encoding.GetString(fileName);
                    name = name.TrimEnd('\0');

                    //Write the file content to a file under the same path of the exe file.
                    stream = (System.IO.MemoryStream)e.Data.GetData("FileContents");
                    System.IO.FileStream fs = new System.IO.FileStream(name, System.IO.FileMode.Create);
                    stream.WriteTo(fs);
                    fs.Close();

                    //Save attachment
                    long             id         = Convert.ToInt64(this.lsvActions.SelectedItems[0].Name);
                    Issue.Action     action     = this.mIssue.Item(id);
                    Issue.Attachment attachment = action.Item(0);
                    attachment.Filename = name;
                    attachment.Save();
                }
            }
            catch (Exception ex) { reportError(ex); }
            finally { setUserServices(); }
        }
예제 #2
0
        private void OnToolbarItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            //Toolbar handler - forward to main menu handler
            long id = 0;

            Issue.Action     action     = null;
            Issue.Attachment attachment = null;
            try {
                //Get the current action
                id     = Convert.ToInt64(this.lsvActions.SelectedItems[0].Name);
                action = this.mIssue.Item(id);
                switch (e.ClickedItem.Name)
                {
                case "btnNew":  this.ctxActionsNew.PerformClick(); break;

                case "btnPrint": this.ctxActionsPrint.PerformClick();  break;

                case "btnRefresh": this.ctxRefresh.PerformClick(); break;

                case "btnOpen":
                    //Open the selected attachment
                    attachment = action.Item(this.lsvAttachments.SelectedItems[0].Text);
                    attachment.Open();
                    break;

                case "btnAttach":
                    //Save an attachment to the selected action
                    OpenFileDialog dlgOpen = new OpenFileDialog();
                    dlgOpen.AddExtension = true;
                    dlgOpen.Filter       = "All Files (*.*) | *.*";
                    dlgOpen.FilterIndex  = 0;
                    dlgOpen.Title        = "Select Attachment to Save...";
                    dlgOpen.FileName     = "";
                    if (dlgOpen.ShowDialog(this) == DialogResult.OK)
                    {
                        attachment          = action.Item(0);
                        attachment.Filename = dlgOpen.FileName;
                        attachment.Save();
                        OnActionSelected(null, EventArgs.Empty);
                    }
                    break;

                case "btnSend":
                    if (this.lsvActions.SelectedItems.Count > 0)
                    {
                        //Create new mail item
                        if (OutlookApp == null)
                        {
                            return;
                        }
                        Outlook.MailItem item = (Outlook.MailItem)OutlookApp.CreateItem(Outlook.OlItemType.olMailItem);
                        item.Subject = this._Issue.Subject;
                        item.Body    = action.Comment;
                        item.To      = EnterpriseFactory.GetContact(this._Issue.ContactID).Email;
                        item.Display(false);
                    }
                    break;
                }
            }
            catch (Exception ex) { reportError(new ControlException("Unexpected error in IssueInspector.", ex)); }
        }
예제 #3
0
        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(); }
        }