Esempio n. 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(); }
        }
Esempio n. 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)); }
        }