Exemple #1
0
        public static void ReassignTask(Outlook.MailItem task)
        {
            //get the recipients of the assigned task
            string[] emails = XLOutlook.EmailAddresses(task);
            //we can only set one in VC so select the first one.
            string newUser = emails[0];

            //if the recipient is not one of us we aren't interested
            if (newUser.Contains("milsted-langdon.co.uk"))
            {
                string fileId = XLOutlook.ReadParameter("VCFileID", task);
                //assign the associated file to the new user
                //get the username from the e-mail address
                newUser = newUser.Substring(0, newUser.IndexOf('@'));
                XLMain.Staff staff = XLMain.Staff.StaffFromUser(newUser);
                //build a reindex command from the data
                string commandfileloc = "";
                commandfileloc = XLVirtualCabinet.Reindex(fileId, staff.name);
                //reindex
                XLVirtualCabinet.BondResult result = XLVirtualCabinet.LaunchCabi(commandfileloc, true, true);
                if (result.ExitCode != 0)
                {
                    //if the reindex is not successful then say so otherwise silence is golden.
                    MessageBox.Show("Reindex failed, possibly because you are offline, please reindex in VC");
                }
            }
        }
Exemple #2
0
        private void ApproveBtn_Click(object sender, RibbonControlEventArgs e)
        {
            Outlook.MailItem email = ThisEmail();
            email.Save();
            XLMain.Client client = XLMain.Client.FetchClient(XLOutlook.ReadParameter("CrmID", email));
            XLMain.Staff  writer = XLMain.Staff.StaffFromUser(Environment.UserName);
            if (XLantRibbon.staff.Count == 0)
            {
                XLantRibbon.staff = XLMain.Staff.AllStaff();
            }
            StaffSelectForm myForm = new StaffSelectForm(client, writer, XLantRibbon.staff);

            myForm.ShowDialog();
            XLMain.EntityCouplet staff = myForm.selectedStaff;

            string commandfileloc = "";

            string fileId = XLOutlook.ReadParameter("VCFileID", email);

            commandfileloc = XLVirtualCabinet.Reindex(fileId, staff.name, status: "Approved", docDate: DateTime.Now.ToString("dd/MM/yyyy"));

            XLVirtualCabinet.BondResult result = XLVirtualCabinet.LaunchCabi(commandfileloc, true);
            if (result.ExitCode != 0)
            {
                MessageBox.Show("Reindex failed please complete manually.");
            }
            else
            {
                // Close the email in Outlook to prevent further changes that won't be saved to VC
                email.Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olSave);
                // Delete the email from the Drafts folder in Outlook
//                email.Delete();
            }
        }
Exemple #3
0
        public static void CheckToDos()
        {
            try
            {
                List <string> newIds = new List <string>();
                //set user
                if (user == null)
                {
                    user = XLMain.Staff.StaffFromUser(Environment.UserName);
                }

                //get the current todos
                List <XLVirtualCabinet.FileInfo> newToDos = XLant.XLVirtualCabinet.GetToDos(user.name);

                //input the ids into an array for comparison with our existing list
                List <string> newtds = new List <string>();
                if (newToDos != null)
                {
                    foreach (XLVirtualCabinet.FileInfo i in newToDos)
                    {
                        //create a list of the ids for comparison
                        //with those already in the system
                        newtds.Add(i.FileID);
                    }
                }
                //get a list of the existing ids if not already filled
                if (ids == null)
                {
                    //build to dos
                    if (ToDoFolder == null)
                    {
                        SetToDoFolder();
                    }
                    foreach (Outlook.TaskItem item in ToDoFolder.Items)
                    {
                        string s = XLOutlook.ReadParameter(fileIdName, item);
                        MessageBox.Show(s);
                        ids.Add(s);
                    }
                }
                //compare the new with the old
                newIds = newtds.Except(ids).ToList();

                //where there are new ones create entries
                foreach (string id in newIds)
                {
                    //go and get the file details
                    XLVirtualCabinet.FileInfo item = XLVirtualCabinet.FileIndex(id);
                    //add to to dos
                    CreateToDo(item);
                }
                ///////////////////need to handle removal of things which have moved other than through XLant/////////////////////
            }
            catch (Exception ex)
            {
                XLant.XLtools.LogException("CheckToDos", ex.ToString());
                MessageBox.Show("Could not check To Dos", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public static void MultiQuickIndex(Outlook.MailItem email, string folder)
        {
            try
            {
                XLant.XLVirtualCabinet.BondResult outcome = IndexEmail(email, folder);
                // As the filing has been successfull, get the FileId returned from Bond via the Standard Output
                if (outcome.ExitCode == 0)
                {
                    string fileid = Regex.Match(outcome.StandardOutput, @"\d+").ToString();
                    XLVirtualCabinet.FileInfo info = XLVirtualCabinet.FileIndex(fileid);
                    DialogResult result            = MessageBox.Show("Do you want to index another copy", "Index", MessageBoxButtons.YesNo);
                    while (result == DialogResult.Yes)
                    {
                        XLForms.ClientForm myForm = new ClientForm();
                        myForm.ShowDialog();
                        XLMain.Client client = myForm.selectedClient;
                        //update the cabinet based on the new client
                        string cabinet = XLVirtualCabinet.FileStore(client.manager.office, client.department);
                        info.Cabinet = cabinet;
                        //update the client field
                        foreach (XLVirtualCabinet.IndexPair pair in info.Indexes)
                        {
                            if (pair.index == "INDEX02")
                            {
                                pair.value = client.clientcode + " - " + client.name;
                            }
                        }
                        outcome = XLVirtualCabinet.IndexDocument(outcome.DocPath, info);

                        if (outcome.ExitCode == 0)
                        {
                            result = MessageBox.Show("Do you want to index another copy", "Index", MessageBoxButtons.YesNo);
                            continue;
                        }
                        else
                        {
                            MessageBox.Show("Unable to index document, please index manually.  Error code: " + outcome.ExitCode.ToString() + "-" + outcome.StandardOutput.ToString());
                            break;
                        }
                    }
                    //update the tick box and category
                    UpdateVCTick(email);
                    //delete email from temp directory
                    if (File.Exists(outcome.DocPath))
                    {
                        File.Delete(outcome.DocPath);
                    }
                }
                else
                {
                    Exception e = new Exception("Unable to index");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to index email");
                XLtools.LogException("MultiQuickIndex", ex.ToString());
            }
        }
        public VCForm(XLMain.Staff writer, XLMain.Client clientPass, string docPathPass, string desc = "", string statusPass = "******", string docDatePass = null, string todo = "user", List <XLMain.EntityCouplet> staffList = null)
        {
            InitializeComponent();
            this.CenterToParent();
            client  = clientPass;
            docPath = docPathPass;
            status  = statusPass;
            docDate = docDatePass ?? DateTime.Now.ToString("dd/MM/yyyy");
            XLMain.Staff user = XLMain.Staff.StaffFromUser(Environment.UserName);

            //Set the list of sections for the cabinet
            List <string> sections = XLVirtualCabinet.SectionValues(client.manager.office, client.department);

            if (sections != null)
            {
                FileSectionDDL.DataSource = sections;
            }
            //if one of the items is correspondence use it otherwise just pick number one.
            try
            {
                FileSectionDDL.SelectedItem = "Correspondence";
            }
            catch
            {
                FileSectionDDL.SelectedIndex = 1;
            }

            DescTB.Text = desc;

            //populate the sender
            List <XLMain.EntityCouplet> users = XLtools.StaffList(user, client, true, userList: staffList);

            if (todo == "user")
            {
                if (writer != null)
                {
                    ToBeActionDDL.DataSource    = users;
                    ToBeActionDDL.DisplayMember = "name";
                    ToBeActionDDL.ValueMember   = "crmID";
                    ToBeActionDDL.SelectedItem  = writer.crmID;
                }
            }
            else
            {
                XLMain.EntityCouplet blank = new XLMain.EntityCouplet();
                blank.crmID = "";
                blank.name  = "";
                users.Insert(0, blank);
                ToBeActionDDL.DataSource    = users;
                ToBeActionDDL.DisplayMember = "name";
                ToBeActionDDL.ValueMember   = "crmID";
                ToBeActionDDL.SelectedItem  = blank;
            }

            //Check for any sub-section
        }
        private void FileSectionDDL_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Check to see whether there are lists attributed to the selected option

            List <XLVirtualCabinet.IndexList> lists = new List <XLVirtualCabinet.IndexList>();

            lists = XLVirtualCabinet.SectionLists(client.office, client.department, FileSectionDDL.SelectedItem.ToString());

            //only allowing up to two other fields
            if (lists != null)
            {
                if (lists.Count > 0)
                {
                    list1                 = lists[0];
                    Listlabel1.Text       = list1.name;
                    ListDDL1.DataSource   = list1.items;
                    ListDDL1.SelectedItem = null;

                    Listlabel1.Visible = true;
                    ListDDL1.Visible   = true;

                    if (lists.Count > 1)
                    {
                        list2               = lists[1];
                        ListLabel2.Text     = list2.name;
                        ListDDL2.DataSource = list2.items;

                        ListLabel2.Visible = true;
                        ListDDL2.Visible   = true;
                    }
                    else
                    {
                        ListLabel2.Visible = false;
                        ListDDL2.Visible   = false;
                    }
                    //Any other detail is not handled - We could have iterated through them but more than two would be a mistake so no need to make it dynamic.
                }
                else
                {
                    Listlabel1.Visible = false;
                    ListDDL1.Visible   = false;
                    ListLabel2.Visible = false;
                    ListDDL2.Visible   = false;
                }
            }
            else
            {
                Listlabel1.Visible = false;
                ListDDL1.Visible   = false;
                ListLabel2.Visible = false;
                ListDDL2.Visible   = false;
            }
        }
        private void IndexBtn_Click(object sender, EventArgs e)
        {
            string folder   = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\XLant\\temp\\";
            string tempPath = folder + "temp.msg";

            email.SaveAs(tempPath);

            string cabinet   = XLVirtualCabinet.FileStore(client.office, client.department);
            string clientStr = client.clientcode + " - " + client.name;
            string status    = "";

            if (email.ReceivedTime != null)
            {
                status = "External";
            }
            else if (email.SentOn != null)
            {
                status = "Sent";
            }
            else
            {
                status = "Draft";
            }
            XLMain.Staff toBe    = (XLMain.Staff)ToBeActionDDL.SelectedItem;
            string       desc    = DescTB.Text;
            string       section = "";

            if (client.department != "INS")
            {
                section = "Correspondence";
            }
            else
            {
                section = FileSectionDDL.SelectedItem.ToString();
            }
            //Launch the index process and collect the result
            XLVirtualCabinet.BondResult outcome = XLVirtualCabinet.IndexDocument(tempPath, cabinet, clientStr, status, toBe.name, section, desc);

            //close the dialog in any event.
            this.Close();
        }
        private void IndexBtn_Click(object sender, EventArgs e)
        {
            string fullPath       = docPath;
            string cabinet        = XLVirtualCabinet.FileStore(client.manager.office, client.department);
            string clientStr      = client.clientcode + " - " + client.name;
            string toBeActionedBy = null;

            if (ToBeActionDDL.SelectedValue == null)
            {
                toBeActionedBy = "";
            }
            else
            {
                XLMain.EntityCouplet toBe = (XLMain.EntityCouplet)ToBeActionDDL.SelectedItem;
                toBeActionedBy = toBe.name;
            }
            //collect information from the two optional ddls use whether they are visible or not to acsertain whether
            //to include them - They may not be visible but still hold data.
            XLVirtualCabinet.IndexPair list1Data = new XLVirtualCabinet.IndexPair();
            XLVirtualCabinet.IndexPair list2Data = new XLVirtualCabinet.IndexPair();
            if (ListDDL1.Visible)
            {
                list1Data.index = list1.index;
                list1Data.value = ListDDL1.Text;
            }
            if (ListDDL2.Visible)
            {
                list2Data.index = list2.index;
                list2Data.value = ListDDL2.Text;
            }

            string desc    = DescTB.Text;
            string section = "";

            section = FileSectionDDL.SelectedItem.ToString();
            //Launch the index process and collect the result
            outcome = XLVirtualCabinet.IndexDocument(fullPath, cabinet, clientStr, status, toBeActionedBy, section, desc, docDate, list1Data, list2Data);

            this.Close();
        }
        public static void IndexAttachments(Outlook.MailItem email)
        {
            if (email.Attachments.Count > 0)
            {
                XLVirtualCabinet.BondResult outcome = new XLVirtualCabinet.BondResult();
                string fileid  = "";
                string docPath = "";
                XLVirtualCabinet.FileInfo info = new XLVirtualCabinet.FileInfo();
                for (int i = 1; i <= email.Attachments.Count; i++)
                {
                    string folder = XLtools.TempPath();
                    if (i == 1)
                    {
                        email.Attachments[i].SaveAsFile(folder + email.Attachments[i].FileName);
                        XLMain.Client selectClient = GetClient(email);
                        //Collect data for indexing
                        XLMain.Staff user = XLMain.Staff.StaffFromUser(Environment.UserName);
                        docPath = folder + email.Attachments[i].FileName;
                        string docDate = DateTime.Now.ToString("dd/MM/yyyy");
                        string status  = "External";
                        string desc    = email.Attachments[i].FileName;
                        if (XLantRibbon.staff.Count == 0)
                        {
                            XLantRibbon.staff = XLMain.Staff.AllStaff();
                        }
                        VCForm indexForm = new VCForm(user, selectClient, docPath, desc, status, docDate, "blank", XLantRibbon.staff);
                        indexForm.ShowDialog();
                        //collect result from form
                        outcome = indexForm.outcome;

                        //get the details of the file.
                        fileid = Regex.Match(outcome.StandardOutput, @"\d+").ToString();
                        info   = XLVirtualCabinet.FileIndex(fileid);

                        //add client to recent list
                        AddClienttoRecent(selectClient);
                    }
                    else
                    {
                        //save the next file
                        email.Attachments[i].SaveAsFile(folder + email.Attachments[i].FileName);
                        docPath = folder + email.Attachments[i].FileName;

                        foreach (XLVirtualCabinet.IndexPair pair in info.Indexes)
                        {
                            if (pair.index.ToUpper() == "INDEX03")
                            {
                                string d = email.Attachments[i].FileName;
                                //generate form for the description to be altered
                                SingleDataCaptureForm myForm = new SingleDataCaptureForm("Input Description", "Enter Description", d);
                                myForm.ShowDialog();
                                if (myForm.result == DialogResult.Cancel)
                                {
                                    continue;
                                }
                                else
                                {
                                    pair.value = myForm.data;
                                }
                            }
                        }
                        outcome = XLVirtualCabinet.IndexDocument(docPath, info);
                    }
                }
                MessageBox.Show("All Attachments Saved");
            }
        }
        public static void OverwriteDraft(Outlook.MailItem email)
        {
            try
            {
                //get the fileID from the stored Parameter
                string fileId = XLOutlook.ReadParameter("VCFileID", email);

                //reindex the email to remove the to be actioned by and update status and doc date
                string commandfileloc = "";
                commandfileloc = XLVirtualCabinet.Reindex(fileId, status: "Sent", docDate: email.SentOn.ToString("dd/MM/yyyy"));

                XLVirtualCabinet.BondResult result = XLVirtualCabinet.LaunchCabi(commandfileloc, true);

                if (result.ExitCode != 0)
                {
                    MessageBox.Show("Reindex failed please complete manually.");
                }
                else
                {
                    //If reindex successful then continue
                    //create a commandfile to reopen the email in edit mode
                    string folderpath      = XLtools.TempPath();
                    string commandfilepath = "";
                    commandfilepath = folderpath + "\\" + (String.Format("{0:yyyy-MM-dd-HH-mm-ss}", DateTime.Now)) + ".bond";
                    StreamWriter commandfile = new StreamWriter(commandfilepath, false, System.Text.Encoding.Default);

                    commandfile.WriteLine("<<MODE=EDIT>>");
                    commandfile.WriteLine("<<INDEX01=" + fileId + ">>");
                    commandfile.WriteLine("<<OPENDOCUMENT=FALSE>>");
                    commandfile.Flush();
                    commandfile.Close();

                    // Call Bond to check out the document
                    result = XLVirtualCabinet.LaunchCabi(commandfilepath, false);
                    // Dispose of the command file object
                    commandfile.Dispose();

                    // Look for the file in the edited documents folder based on the FileId
                    List <string> msgfile    = new List <string>();
                    string[]      Files      = Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Virtual Cabinet\\Edited documents");
                    int           FilesCount = Files.Length;

                    // Collect all the entries which match the fileID
                    for (int i = 0; i < FilesCount; i++)
                    {
                        string f = Files[i].ToString();

                        if (Path.GetFileName(f).StartsWith(fileId + "-"))
                        {
                            msgfile.Add(f);
                        }
                    }
                    //There should only be 1 if there are more something has gone wrong. We don't want to overwrite the wrong one so exit
                    if (msgfile.Count != 1)
                    {
                        Exception exception = new Exception("Unable to find the draft email message.");
                    }
                    else
                    {
                        // Delete the old version and save the sent email in the default MSG format
                        if (File.Exists(msgfile[0]))
                        {
                            File.Delete(msgfile[0]);
                        }
                        email.SaveAs(msgfile[0]);

                        // Create a command file to save the document as a new version based on the FileId
                        commandfilepath = folderpath + "\\" + (String.Format("{0:yyyy-MM-dd-HH-mm-ss}", DateTime.Now)) + ".bond";
                        commandfile     = new StreamWriter(commandfilepath, false, System.Text.Encoding.Default);
                        commandfile.WriteLine("<<MODE=SAVE>>");
                        commandfile.WriteLine("<<INDEX01=" + fileId + ">>");
                        commandfile.Flush();
                        commandfile.Close();

                        // Call Bond to save the email back to VC
                        result = XLVirtualCabinet.LaunchCabi(commandfilepath, false);
                        // Dispose of the command file object
                        commandfile.Dispose();
                        //update the tick box
                        UpdateVCTick(email);
                        //Mark email as saved.
                        email.UnRead = false;
                        //Close and save
                        email.Close(Outlook.OlInspectorClose.olSave);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to update e-mail");
                XLtools.LogException("OverwriteDraft", ex.ToString());
            }
        }
        public static void IndexDraft(Outlook.MailItem email)
        {
            try
            {
                XLant.XLVirtualCabinet.BondResult outcome = IndexEmail(email, "Draft");

                if (outcome.ExitCode != 0)
                {
                    MessageBox.Show("Unable to index document, please index manually.  Error code: " + outcome.ExitCode.ToString() + "-" + outcome.StandardOutput.ToString());
                }
                else
                {
                    UpdateVCTick(email);
                    // As the filing has been successfull, get the FileId returned from Bond via the Standard Output
                    string fileid          = Regex.Match(outcome.StandardOutput, @"\d+").ToString();
                    string folderpath      = XLtools.TempPath();
                    string commandfilepath = "";
                    commandfilepath = folderpath + "\\" + (String.Format("{0:yyyy-MM-dd-HH-mm-ss}", DateTime.Now)) + ".bond";
                    StreamWriter commandfile = new StreamWriter(commandfilepath, false, System.Text.Encoding.Default);

                    commandfile.WriteLine("<<MODE=EDIT>>");
                    commandfile.WriteLine("<<INDEX01=" + fileid + ">>");
                    commandfile.WriteLine("<<OPENDOCUMENT=FALSE>>");
                    commandfile.Flush();
                    commandfile.Close();

                    // Call Bond to check out the document
                    XLVirtualCabinet.BondResult result = XLVirtualCabinet.LaunchCabi(commandfilepath, false);
                    // Dispose of the command file object
                    commandfile.Dispose();

                    // Look for the file in the edited documents folder based on the FileId
                    List <string> msgfile    = new List <string>();
                    string[]      Files      = Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Virtual Cabinet\\Edited documents");
                    int           FilesCount = Files.Length;

                    // Collect all the entries which match the fileID
                    for (int i = 0; i < FilesCount; i++)
                    {
                        string f = Files[i].ToString();

                        if (Path.GetFileName(f).StartsWith(fileid + "-"))
                        {
                            msgfile.Add(f);
                        }
                    }

                    if (msgfile.Count != 1)
                    {
                        Exception exception = new Exception("Unable to find the mail message.  Your file has been indexed but could not have the file ID added.");
                    }
                    else
                    {
                        // Add the Virtual Cabinet FileId to the Subject of the email (still open on screen)
                        // UserProperties and Custom Headers do not persist, so using something that does. Body could be another option.
                        XLOutlook.UpdateParameter("VCFileID", fileid, email);
                        //email.Subject = email.Subject + @" FileId:" + fileid.ToString();

                        // Save the MailItem
                        email.Save();

                        // Save the email in the default MSG format
                        if (File.Exists(msgfile[0]))
                        {
                            File.Delete(msgfile[0]);
                        }
                        email.SaveAs(msgfile[0]);

                        // Create a command file to save the document as a new version based on the FileId
                        commandfilepath = folderpath + "\\" + (String.Format("{0:yyyy-MM-dd-HH-mm-ss}", DateTime.Now)) + ".bond";
                        commandfile     = new StreamWriter(commandfilepath, false, System.Text.Encoding.Default);
                        commandfile.WriteLine("<<MODE=SAVE>>");
                        commandfile.WriteLine("<<INDEX01=" + fileid + ">>");
                        commandfile.Flush();
                        commandfile.Close();

                        // Call Bond to save the email back to VC
                        result = XLVirtualCabinet.LaunchCabi(commandfilepath, false);
                        // Dispose of the command file object
                        commandfile.Dispose();

                        // Close the email in Outlook to prevent further changes that won't be saved to VC
                        email.Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olSave);

                        // Delete the email from the Drafts folder in Outlook
                        email.UnRead = false;
                        email.Delete();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to index draft email");
                XLtools.LogException("IndexDraft", ex.ToString());
            }
        }