Esempio n. 1
0
        private void btn_execute_Click(object sender, EventArgs e)
        {
            MainFormValues mfv = new MainFormValues(txt_existingPassword.Text, txt_password.Text, txt_targetFolder.Text, txt_outputFolderPath.Text);

            //TODO this will not work with grouping emails
            if (GroupBy)
            {
                int max = fileData.GroupBy(o => o.Site).Count();
                progressBar1.Maximum = max;
            }
            else
            {
                progressBar1.Maximum = fileData.Count;
            }

            progressBar1.Minimum = 0;
            progressBar1.Step    = 1;
            progressBar1.Value   = 0;
            backgroundWorker1.RunWorkerAsync(mfv);
            btn_execute.Enabled = false;
        }
Esempio n. 2
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            MainFormValues mfv = (MainFormValues)e.Argument;

            PdfTools pt = new PdfTools();

            string encryptedFile = string.Empty;

            //perform encryption and save copy if indicated on main form.
            if (Encrypt)
            {
                foreach (FileData fd in fileData)
                {
                    try
                    {
                        string tempFile = tempFolder + fd.FileName;

                        if (pt.IsEncrypted(fd.FullFileName))
                        {
                            string decryptedFile = pt.DecryptPdf(fd.FullFileName, tempFile, mfv.ExistingPassword);

                            if (SaveCopy)
                            {
                                encryptedFile = mfv.SaveAsPath + @"\" + fd.NewFileName;
                                pt.EncryptPdf(decryptedFile, encryptedFile, mfv.Password);
                            }
                            else
                            {
                                encryptedFile = mfv.TargetPath + @"\" + fd.NewFileName;
                                pt.EncryptPdf(decryptedFile, encryptedFile, mfv.Password);
                            }
                        }
                        else
                        {
                            if (SaveCopy)
                            {
                                encryptedFile = mfv.SaveAsPath + @"\" + fd.NewFileName;
                                pt.EncryptPdf(fd.FullFileName, encryptedFile, mfv.Password);
                            }
                            else
                            {
                                encryptedFile = mfv.TargetPath + @"\" + fd.NewFileName;
                                pt.EncryptPdf(fd.FullFileName, encryptedFile, mfv.Password);
                            }
                        }

                        fd.FinalLocationForEmail = encryptedFile;
                    }catch (Exception)
                    {
                        //TODO indicate something went wrong.
                    }

                    backgroundWorker1.ReportProgress(0);
                }
            }
            //TODO this is where Decrpyt only code would go.  Possilby an HR need at some point.

            //send email of attachment and group together if toggled.
            if (Email)
            {
                if (GroupBy)
                {
                    foreach (DirectorData dd in directorData)
                    {
                        attachments.Clear();

                        foreach (FileData fd in fileData)
                        {
                            if (fd.Site == dd.Site)
                            {
                                attachments.Add(fd.FinalLocationForEmail);
                            }
                        }

                        if (attachments.Count > 0)
                        {
                            EmailTools et = new EmailTools(dd.Email, attachments);

                            if (Outlook)
                            {
                                et.SendEmailOutlook();
                            }
                            else
                            {
                                et.SendEmailExchange();
                            }
                        }
                    }
                }
                else
                {
                    foreach (FileData fd in fileData)
                    {
                        EmailTools et = new EmailTools(fd.Email, fd.FinalLocationForEmail);

                        if (Outlook)
                        {
                            et.SendEmailOutlook();
                        }
                        else
                        {
                            et.SendEmailExchange();
                        }
                    }
                }

                if (!SaveCopy)
                {
                    foreach (FileData item in fileData)
                    {
                        File.Delete(item.FinalLocationForEmail);
                    }
                }
            }
        }