Пример #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
                        string name = new System.IO.FileInfo(names[0]).Name;
                        System.IO.FileStream stream = new System.IO.FileStream(names[0], System.IO.FileMode.Open);
                        byte[] bytes = new byte[stream.Length];
                        //stream.Position = 0;
                        stream.Read(bytes, 0, (int)stream.Length);
                        long actionID = Convert.ToInt64(this.lsvActions.SelectedItems[0].Name);
                        CustomerProxy.CreateIssueAttachment(name, bytes, actionID);
                        stream.Close();
                        loadActions();
                    }
                }
                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');
                    stream.Close();

                    //Save attachment
                    stream = (System.IO.MemoryStream)e.Data.GetData("FileContents");
                    byte[] bytes = new byte[stream.Length];
                    //stream.Position = 0;
                    stream.Read(bytes, 0, (int)stream.Length);
                    long actionID = Convert.ToInt64(this.lsvActions.SelectedItems[0].Name);
                    CustomerProxy.CreateIssueAttachment(name, bytes, actionID);
                    stream.Close();
                    loadActions();
                }
            }
            catch (Exception ex) { reportError(ex); }
            finally { setUserServices(); }
        }
Пример #2
0
        private void OnToolbarItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            //Toolbar handler - forward to main menu handler
            long   actionID = 0;
            Action action   = null;

            System.IO.FileStream fs = null;
            byte[] bytes            = null;
            try {
                //Get the current action
                actionID = Convert.ToInt64(this.lsvActions.SelectedItems[0].Name);
                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
                    int attachmentID = Convert.ToInt32(this.lsvAttachments.SelectedItems[0].Name);
                    bytes = CustomerProxy.GetAttachment(attachmentID);
                    string file = CustomerProxy.TempFolder + this.lsvAttachments.SelectedItems[0].Text.Trim();
                    fs = new System.IO.FileStream(file, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
                    System.IO.BinaryWriter writer = new System.IO.BinaryWriter(fs);
                    writer.Write(bytes);
                    writer.Flush();
                    writer.Close();
                    System.Diagnostics.Process.Start(file);
                    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)
                    {
                        string name = new System.IO.FileInfo(dlgOpen.FileName).Name;
                        fs = new System.IO.FileStream(dlgOpen.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                        System.IO.BinaryReader reader = new System.IO.BinaryReader(fs);
                        bytes = reader.ReadBytes((int)fs.Length);
                        reader.Close();
                        bool created = CustomerProxy.CreateIssueAttachment(name, bytes, actionID);
                        loadActions();
                    }
                    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.mIssue.Subject;
                        item.Body    = action.Comment;
                        item.To      = CustomerProxy.GetContact(this.mIssue.ContactID).Email;
                        item.Display(false);
                    }
                    break;
                }
            }
            catch (Exception ex) { reportError(new ControlException("Unexpected error in IssueInspector.", ex)); }
            finally { if (fs != null)
                      {
                          fs.Close();
                      }
            }
        }