示例#1
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();
                      }
            }
        }