private void ProcessCommandLine(string[] args)
        {
            MSUtils util = new MSUtils();

            string invalidSwitchMessage = string.Concat("*** ERROR ***: Invalid switch {0}!", Environment.NewLine);

            switch (args.Length)
            {
                case 0:
                    Console.WriteLine(CopyrightsStr());
                    Console.WriteLine(UsageStr());
                    break;
                case 1:
                    if (args[0].ToUpper().Trim() != "-H")
                    {
                        Console.WriteLine(string.Format(invalidSwitchMessage, args[0]));
                    } 

                    Console.WriteLine(UsageStr());
                    break;
                default:
                    string option = args[0].ToUpper().Trim();

                    if (option == "-S")
                    {
                        string destFolder = Environment.CurrentDirectory;

                        if (args.Length > 2)
                        {
                            destFolder = args[2];
                        }

                        util.ConvertToSinglePageTiffs(args[1].Trim(), destFolder);
                    }
                    else if (option == "-O")
                    {
                        if (args.Length < 4 || args[2].ToUpper().Trim() != "-M")
                        {
                            Console.WriteLine(string.Format(invalidSwitchMessage, "options"));
                        }
                        else
                        {
                            string destFile = args[1].Trim();
                            List<string> fileList = new List<string>();

                            for (int i = 3; i < args.Length; i++)
                            {
                                fileList.Add(args[i]);
                            }

                            util.ConvertToMultiPageTiff(fileList, destFile);
                        }
                    }
                    else if (option == "-C")
                    {
                        if (args.Length != 2)
                        {
                            Console.WriteLine(string.Format(invalidSwitchMessage, "options"));
                        }
                        else
                        {
                            if (!File.Exists(args[1]))
                            {
                                Console.WriteLine(String.Format("*** ERROR ***: Configuration File {0} does not exist.", args[1]));
                            }
                            else
                            {
                                Config cfg = new Config();
                                string err = string.Empty;
                                ConfigurationValues values = cfg.GetConfigurations(args[1],ref err);

                                if (err != string.Empty) Console.WriteLine(err);

                                string[] fns = values.InputFiles.Split(';');
                                switch (values.Action)
                                {                                        
                                    case Config.ACTION_SPLIT:                                        
                                        foreach (string fn in fns)
                                        {
                                            util.ConvertToSinglePageTiffs(Path.Combine(values.SrcDir,fn), Path.Combine(values.DestDir,Path.GetFileNameWithoutExtension(fn)));
                                        }
                                        break;
                                    case Config.ACTION_MERGE:
                                        fns = values.InputFiles.Split(';');
                                        List<string> list = new List<string>();
                                        foreach (string fn in fns)
                                        {
                                            Console.WriteLine(values.SrcDir);
                                            list.Add(Path.Combine(values.SrcDir, fn));                                     
                                        }
                                        util.ConvertToMultiPageTiff(list, Path.Combine(values.DestDir,values.OutputFile));
                                        break;
                                    default:
                                        Console.WriteLine(String.Format("*** ERROR ***: Unrecognized configuration key {0}.", values.Action));
                                        break;
                                }
                            }
                        }
                    }
                    break;
            }
        }
        private void frmMain_Load(object sender, EventArgs e)
        {
            MSUtils util = new MSUtils();

            try
            {
                Common.DeleteFilesFromFolder(Application.StartupPath + "\\temp2");
            }
            catch (Exception er)
            {
                MessageBox.Show(er.Message,
                    "Edits", MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation);
            }

            try
            {
                Common.DeleteFilesFromFolder(Application.StartupPath + "\\temp1");
            }
            catch (Exception er)
            {
                MessageBox.Show(er.Message,
                    "Edits", MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation);
            }

            _chargeSlipNumber = ClipBoardHelper.GetText();

            GetOtherParameters(_chargeSlipNumber);

            int _docNumber = 1;
            string _docID = string.Empty;
            string _patientId = string.Empty;

            string _sql = "select d.personid, d.documentid, p.sharedid as AccountNumber, d.encounterdate as AppointmentDateTime"
                + " from documents d"
                + " join person p on d.personid = p.personid"
                + " where p.sharedid = '" + _sharedID + "'"
                + " and d.encounterdate = '" + _date + "'"
                + " and d.isdeleted = 0 "
                + " and  d.documenttypeid = 'doc'";

            /*
            string _sql = "select d.personid, d.documentid, p.sharedid as AccountNumber, d.encounterdate as AppointmentDateTime"
                + " from documents d"
                + " join person p on d.personid = p.personid"
                + " where p.sharedid = '295363' "
                + " and d.encounterdate = '8/1/2011' "
                + " and d.isdeleted = 0 "
                + " and  d.documenttypeid = 'doc'";
         //   */
            //p.sharedid = '295363' and d.encounterdate = '8/1/2011'

            radRichTextBox1.Height = this.Height - 100;
            radRichTextBox2.Height = this.Height - 100;
            radRichTextBox3.Height = this.Height - 100;
            radRichTextBox4.Height = this.Height - 100;
            radRichTextBox5.Height = this.Height - 100;
            radRichTextBox6.Height = this.Height - 100;
            radRichTextBox7.Height = this.Height - 100;
            radRichTextBox8.Height = this.Height - 100;
            radRichTextBox9.Height = this.Height - 100;
            radRichTextBox10.Height = this.Height - 100;

            tabsDocuments.TabPages.Clear();

            try
            {
                using (SqlConnection cn = new SqlConnection(Database.SRSConnection))
                {
                    cn.Open();
                    using (SqlCommand cm = cn.CreateCommand())
                    {
                        cm.CommandText = _sql;
                        SqlDataReader dr = cm.ExecuteReader();
                        while (dr.Read())
                        {
                            _documentsSelected = 2;
                            double _dPatientId = 0;
                            double _ddocID = 0;
                            _dPatientId = dr.GetDouble(0);
                            _patientId = _dPatientId.ToString();
                            _ddocID = dr.GetDouble(1);
                            _docID = _ddocID.ToString();
                            if (_docNumber == 1)
                            {
                                tabsDocuments.TabPages.Add(tabDocument1);
                                ckdocument1.Visible = true;

                                Debug.WriteLine("\\\\srsfile\\SRSServer\\Storage\\" + _patientId.Substring(0, 2) + "\\" + _patientId + "\\" + _docID);
                              //  File.Copy("\\\\srsfile\\SRSServer\\Storage\\" + _patientId.Substring(0, 2) + "\\" + _patientId + "\\" + _docID,"D:\\2.doc");
                                try
                                {
                                    //File.Copy("\\\\srsfile\\SRSServer\\Storage\\" + _patientId.Substring(0, 2) + "\\" + _patientId + "\\" + _docID, Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                    File.Copy("\\\\srsfile\\SRSServer\\Storage\\" + _patientId.Substring(0, 2) + "\\" + _patientId + "\\" + _docID, Application.StartupPath + "\\temp1\\" + _docID + ".doc");



                                    //File.Copy("\\\\srsfile\\SRSServer\\Storage\\" + _patientId.Substring(0, 2) + "\\" + _patientId + "\\" + _docID, Application.StartupPath + "\\temp1\\" + _docID + ".doc");

                                    radRichTextBox1.Document = ImportDocx(Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                    _document1Path = Application.StartupPath + "\\temp1\\" + _docID + ".doc";
                                    _docNumber++;
                                }
                                catch (Exception er)
                                {
                                    MessageBox.Show("Error Message is " + er.Message ,"Error", MessageBoxButtons.OK);
                                }
                            }
                            else if (_docNumber == 2)
                            {
                                tabsDocuments.TabPages.Add(tabDocument2);
                                ckdocument2.Visible = true;

                                Debug.WriteLine("\\\\srsfile\\SRSServer\\Storage\\" + _patientId.Substring(0, 2) + "\\" + _patientId + "\\" + _docID);

                                try
                                {
                                    File.Copy("\\\\srsfile\\SRSServer\\Storage\\" + _patientId.Substring(0, 2) + "\\" + _patientId + "\\" + _docID, Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                    //radRichTextBox2.Navigate(Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                    radRichTextBox2.Document = ImportDocx(Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                    _document2Path = Application.StartupPath + "\\temp1\\" + _docID + ".doc";
                                    _docNumber++;
                                }
                                catch (Exception er)
                                {
                                    MessageBox.Show("Error Message is " + er.Message, "Error", MessageBoxButtons.OK);
                                }
                            }
                            else if (_docNumber == 3)
                            {
                                tabsDocuments.TabPages.Add(tabDocument3);
                                ckdocument3.Visible = true;

                                Debug.WriteLine("\\\\srsfile\\SRSServer\\Storage\\" + _patientId.Substring(0, 2) + "\\" + _patientId + "\\" + _docID);

                                try
                                {
                                    File.Copy("\\\\srsfile\\SRSServer\\Storage\\" + _patientId.Substring(0, 2) + "\\" + _patientId + "\\" + _docID, Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                   // radRichTextBox3.Navigate(Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                    radRichTextBox3.Document = ImportDocx(Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                    _document3Path = Application.StartupPath + "\\temp1\\" + _docID + ".doc";
                                    _docNumber++;
                                }
                                catch (Exception er)
                                {
                                    MessageBox.Show("Error Message is " + er.Message, "Error", MessageBoxButtons.OK);
                                }
                            }
                            else if (_docNumber == 4)
                            {
                                tabsDocuments.TabPages.Add(tabDocument4);
                                ckdocument4.Visible = true;

                                Debug.WriteLine("\\\\srsfile\\SRSServer\\Storage\\" + _patientId.Substring(0, 2) + "\\" + _patientId + "\\" + _docID);

                                try
                                {
                                    File.Copy("\\\\srsfile\\SRSServer\\Storage\\" + _patientId.Substring(0, 2) + "\\" + _patientId + "\\" + _docID, Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                    //radRichTextBox14.Navigate(Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                    radRichTextBox4.Document = ImportDocx(Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                    _document4Path = Application.StartupPath + "\\temp1\\" + _docID + ".doc";
                                    _docNumber++;
                                }
                                catch (Exception er)
                                {
                                    MessageBox.Show("Error Message is " + er.Message, "Error", MessageBoxButtons.OK);
                                }
                            }
                            else if (_docNumber == 5)
                            {
                                tabsDocuments.TabPages.Add(tabDocument5);
                                ckdocument5.Visible = true;

                                Debug.WriteLine("\\\\srsfile\\SRSServer\\Storage\\" + _patientId.Substring(0, 2) + "\\" + _patientId + "\\" + _docID);

                                try
                                {
                                    File.Copy("\\\\srsfile\\SRSServer\\Storage\\" + _patientId.Substring(0, 2) + "\\" + _patientId + "\\" + _docID, Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                    radRichTextBox5.Document = ImportDocx(Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                    //radRichTextBox.Navigate(Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                    _document5Path = Application.StartupPath + "\\temp1\\" + _docID + ".doc";
                                    _docNumber++;
                                }
                                catch (Exception er)
                                {
                                    MessageBox.Show("Error Message is " + er.Message, "Error", MessageBoxButtons.OK);
                                }
                            }
                            else if (_docNumber == 6)
                            {
                                tabsDocuments.TabPages.Add(tabDocument6);
                                ckdocument6.Visible = true;

                                Debug.WriteLine("\\\\srsfile\\SRSServer\\Storage\\" + _patientId.Substring(0, 2) + "\\" + _patientId + "\\" + _docID);

                                try
                                {
                                    File.Copy("\\\\srsfile\\SRSServer\\Storage\\" + _patientId.Substring(0, 2) + "\\" + _patientId + "\\" + _docID, Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                    //radRichTextBox6.Navigate(Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                    radRichTextBox6.Document = ImportDocx(Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                    _document6Path = Application.StartupPath + "\\temp1\\" + _docID + ".doc";
                                    _docNumber++;
                                }
                                catch (Exception er)
                                {
                                    MessageBox.Show("Error Message is " + er.Message, "Error", MessageBoxButtons.OK);
                                }
                            }
                            else if (_docNumber == 7)
                            {
                                tabsDocuments.TabPages.Add(tabDocument7);
                                ckdocument7.Visible = true;

                                Debug.WriteLine("\\\\srsfile\\SRSServer\\Storage\\" + _patientId.Substring(0, 2) + "\\" + _patientId + "\\" + _docID);

                                try
                                {
                                    File.Copy("\\\\srsfile\\SRSServer\\Storage\\" + _patientId.Substring(0, 2) + "\\" + _patientId + "\\" + _docID, Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                    //radRichTextBox7.Navigate(Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                    radRichTextBox7.Document = ImportDocx(Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                    _document7Path = Application.StartupPath + "\\temp1\\" + _docID + ".doc";
                                    _docNumber++;
                                }
                                catch (Exception er)
                                {
                                    MessageBox.Show("Error Message is " + er.Message, "Error", MessageBoxButtons.OK);
                                }
                            }
                            else if (_docNumber == 8)
                            {
                                tabsDocuments.TabPages.Add(tabDocument8);
                                ckdocument8.Visible = true;

                                Debug.WriteLine("\\\\srsfile\\SRSServer\\Storage\\" + _patientId.Substring(0, 2) + "\\" + _patientId + "\\" + _docID);

                                try
                                {
                                    File.Copy("\\\\srsfile\\SRSServer\\Storage\\" + _patientId.Substring(0, 2) + "\\" + _patientId + "\\" + _docID, Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                    //radRichTextBox8.Navigate(Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                    radRichTextBox8.Document = ImportDocx(Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                    _document8Path = Application.StartupPath + "\\temp1\\" + _docID + ".doc";
                                    _docNumber++;
                                }
                                catch (Exception er)
                                {
                                    MessageBox.Show("Error Message is " + er.Message, "Error", MessageBoxButtons.OK);
                                }
                            }
                            else if (_docNumber == 9)
                            {
                                tabsDocuments.TabPages.Add(tabDocument9);
                                ckdocument9.Visible = true;

                                Debug.WriteLine("\\\\srsfile\\SRSServer\\Storage\\" + _patientId.Substring(0, 2) + "\\" + _patientId + "\\" + _docID);

                                try
                                {
                                    File.Copy("\\\\srsfile\\SRSServer\\Storage\\" + _patientId.Substring(0, 2) + "\\" + _patientId + "\\" + _docID, Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                    //radRichTextBox9.Navigate(Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                    radRichTextBox9.Document = ImportDocx(Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                    _document9Path = Application.StartupPath + "\\temp1\\" + _docID + ".doc";
                                    _docNumber++;
                                }
                                catch (Exception er)
                                {
                                    MessageBox.Show("Error Message is " + er.Message, "Error", MessageBoxButtons.OK);
                                }
                            }
                            else if (_docNumber == 10)
                            {
                                tabsDocuments.TabPages.Add(tabDocument10);
                                ckdocument10.Visible = true;

                                //Debug.WriteLine("\\\\srsfile\\SRSServer\\Storage\\" + _patientId.Substring(0, 2) + "\\" + _patientId + "\\" + _docID);

                                try
                                {
                                    //File.Copy("\\\\srsfile\\SRSServer\\Storage\\" + _patientId.Substring(0, 2) + "\\" + _patientId + "\\" + _docID, Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                    File.Copy("\\\\srsfile\\SRSServer\\Storage\\" + _patientId.Substring(0, 2) + "\\" + _patientId + "\\" + _docID, Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                    
                                    //radRichTextBox10.Navigate(Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                    radRichTextBox10.Document = ImportDocx(Application.StartupPath + "\\temp1\\" + _docID + ".doc");
                                    _document10Path = Application.StartupPath + "\\temp1\\" + _docID + ".doc";
                                    _docNumber++;
                                }
                                catch (Exception er)
                                {
                                    MessageBox.Show("Error Message is " + er.Message, "Error", MessageBoxButtons.OK);
                                }
                            }
                        };
                        //return dr.GetInt32(0);
                    }
                    if (_documentsSelected == 1)
                    {
                        MessageBox.Show("No Documents",
                          "No Documents ", MessageBoxButtons.OK,
                          MessageBoxIcon.Exclamation);
                        KillWordForWindows();
                        Application.Exit();
                        return;
                    }
                }
            }
            catch (Exception er)
            {
                MessageBox.Show("Error Message is " + er.Message, "Error", MessageBoxButtons.OK);
            }

        }
        private void BtnConvert_Click(object sender, EventArgs e)
        {
            List<string> files = new List<string>();

            foreach (object o in FileList.Items)
            {
                files.Add(o as string);
            }

            if (files.Count == 0) return;

            Cursor = Cursors.WaitCursor;
            try
            {

                MSUtils util = new MSUtils();

                if (RdoMultiToSingle.Checked)
                {

                    foreach (string fn in files)
                    {
                        util.ConvertToSinglePageTiffs(fn, Path.GetFileNameWithoutExtension(fn));
                    }
                }
                else
                {
                    util.ConvertToMultiPageTiff(files, OutputFileNameTextBox.Text);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Cursor = Cursors.Default;
                MessageBox.Show("The selected files has been successfully processed.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private void buttonSend_Click(object sender, EventArgs e)
        {
            if (_checkedDocument)
            {

            }
            else
            {
                MessageBox.Show("No Documents Selected",
                  "No Documents Selected", MessageBoxButtons.OK,
                  MessageBoxIcon.Exclamation);
                KillWordForWindows();
                Application.Exit();
                return;
            }

            util = new MSUtils();

            if (ckdocument1.Checked == true)
            {

                File.Copy(_document1Path, Application.StartupPath + "\\temp1\\document1.doc",true );

                Stream _readFile = new FileStream(Application.StartupPath + "\\temp1\\document1.doc", FileMode.Open, FileAccess.Read, FileShare.Read);
                WordDocument _wordDocument = new WordDocument(_readFile);
                DocToPDFConverter _converter = new DocToPDFConverter();
                //Convert word document into PDF document
                PdfDocument _pdfDocument = _converter.ConvertToPDF(_wordDocument);
                _pdfDocument.Save(Application.StartupPath + "\\temp1\\document1.pdf");

                PDFFile _file =
                    PDFFile.Open(Application.StartupPath + "\\temp1\\document1.pdf");

                _file.SerialNumber = "PDFVW-Y11DV-6VYTH-TWHXK-6DRLB-7MNQB";

                for (int i = 0; i < _file.PageCount; i++)
                {
                    // Convert each page to bitmap and save it.
                    Bitmap pageImage = _file.GetPageImage(i, 96);
                    pageImage.Save(Application.StartupPath + "\\temp2\\document1" + i.ToString() + ".tif", ImageFormat.Tiff);
                    _listOfTifs.Add(Application.StartupPath + "\\temp2\\document1" + i.ToString() + ".tif");
                }

                _file.Dispose();
                _readFile.Close();
                _readFile.Dispose(); 
            }
            if (ckdocument2.Checked == true)
            {

                File.Copy(_document2Path, Application.StartupPath + "\\temp1\\document2.doc", true);

                Stream _readFile = new FileStream(Application.StartupPath + "\\temp1\\document2.doc", FileMode.Open, FileAccess.Read, FileShare.Read);
                WordDocument _wordDocument = new WordDocument(_readFile);
                DocToPDFConverter _converter = new DocToPDFConverter();
                //Convert word document into PDF document
                PdfDocument _pdfDocument = _converter.ConvertToPDF(_wordDocument);
                _pdfDocument.Save(Application.StartupPath + "\\temp1\\document2.pdf");

                PDFFile _file =
                    PDFFile.Open(Application.StartupPath + "\\temp1\\document2.pdf");

                _file.SerialNumber = "PDFVW-Y11DV-6VYTH-TWHXK-6DRLB-7MNQB";

                for (int i = 0; i < _file.PageCount; i++)
                {
                    // Convert each page to bitmap and save it.
                    Bitmap pageImage = _file.GetPageImage(i, 96);
                    pageImage.Save(Application.StartupPath + "\\temp2\\document2" + i.ToString() + ".tif", ImageFormat.Tiff);
                    _listOfTifs.Add(Application.StartupPath + "\\temp2\\document2" + i.ToString() + ".tif");
                }

                _file.Dispose();
                _readFile.Close();
                _readFile.Dispose();
            }
            if (ckdocument3.Checked == true)
            {

                File.Copy(_document3Path, Application.StartupPath + "\\temp1\\document3.doc", true);

                Stream _readFile = new FileStream(Application.StartupPath + "\\temp1\\document3.doc", FileMode.Open, FileAccess.Read, FileShare.Read);
                WordDocument _wordDocument = new WordDocument(_readFile);
                DocToPDFConverter _converter = new DocToPDFConverter();
                //Convert word document into PDF document
                PdfDocument _pdfDocument = _converter.ConvertToPDF(_wordDocument);
                _pdfDocument.Save(Application.StartupPath + "\\temp1\\document3.pdf");

                PDFFile _file =
                    PDFFile.Open(Application.StartupPath + "\\temp1\\document3.pdf");

                _file.SerialNumber = "PDFVW-Y11DV-6VYTH-TWHXK-6DRLB-7MNQB";

                for (int i = 0; i < _file.PageCount; i++)
                {
                    // Convert each page to bitmap and save it.
                    Bitmap pageImage = _file.GetPageImage(i, 96);
                    pageImage.Save(Application.StartupPath + "\\temp2\\document3" + i.ToString() + ".tif", ImageFormat.Tiff);
                    _listOfTifs.Add(Application.StartupPath + "\\temp2\\document3" + i.ToString() + ".tif");
                }

                _file.Dispose();
                _readFile.Close();
                _readFile.Dispose();
            }
            if (ckdocument4.Checked == true)
            {
                File.Copy(_document4Path, Application.StartupPath + "\\temp1\\document4.doc", true);

                Stream _readFile = new FileStream(Application.StartupPath + "\\temp1\\document4.doc", FileMode.Open, FileAccess.Read, FileShare.Read);
                WordDocument _wordDocument = new WordDocument(_readFile);
                DocToPDFConverter _converter = new DocToPDFConverter();
                //Convert word document into PDF document
                PdfDocument _pdfDocument = _converter.ConvertToPDF(_wordDocument);
                _pdfDocument.Save(Application.StartupPath + "\\temp1\\document4.pdf");

                PDFFile _file =
                    PDFFile.Open(Application.StartupPath + "\\temp1\\document4.pdf");

                _file.SerialNumber = "PDFVW-Y11DV-6VYTH-TWHXK-6DRLB-7MNQB";

                for (int i = 0; i < _file.PageCount; i++)
                {
                    // Convert each page to bitmap and save it.
                    Bitmap pageImage = _file.GetPageImage(i, 96);
                    pageImage.Save(Application.StartupPath + "\\temp2\\document4" + i.ToString() + ".tif", ImageFormat.Tiff);
                    _listOfTifs.Add(Application.StartupPath + "\\temp2\\document4" + i.ToString() + ".tif");
                }

                _file.Dispose();
                _readFile.Close();
                _readFile.Dispose();
            }
            if (ckdocument5.Checked == true)
            {

                File.Copy(_document5Path, Application.StartupPath + "\\temp1\\document5.doc", true);

                Stream _readFile = new FileStream(Application.StartupPath + "\\temp1\\document5.doc", FileMode.Open, FileAccess.Read, FileShare.Read);
                WordDocument _wordDocument = new WordDocument(_readFile);
                DocToPDFConverter _converter = new DocToPDFConverter();
                //Convert word document into PDF document
                PdfDocument _pdfDocument = _converter.ConvertToPDF(_wordDocument);
                _pdfDocument.Save(Application.StartupPath + "\\temp1\\document5.pdf");

                PDFFile _file =
                    PDFFile.Open(Application.StartupPath + "\\temp1\\document5.pdf");

                _file.SerialNumber = "PDFVW-Y11DV-6VYTH-TWHXK-6DRLB-7MNQB";

                for (int i = 0; i < _file.PageCount; i++)
                {
                    // Convert each page to bitmap and save it.
                    Bitmap pageImage = _file.GetPageImage(i, 96);
                    pageImage.Save(Application.StartupPath + "\\temp2\\document5" + i.ToString() + ".tif", ImageFormat.Tiff);
                    _listOfTifs.Add(Application.StartupPath + "\\temp2\\document5" + i.ToString() + ".tif");
                }

                _file.Dispose();
                _readFile.Close();
                _readFile.Dispose();
            }
            if (ckdocument6.Checked == true)
            {

                File.Copy(_document6Path, Application.StartupPath + "\\temp1\\document6.doc", true);

                Stream _readFile = new FileStream(Application.StartupPath + "\\temp1\\document6.doc", FileMode.Open, FileAccess.Read, FileShare.Read);
                WordDocument _wordDocument = new WordDocument(_readFile);
                DocToPDFConverter _converter = new DocToPDFConverter();
                //Convert word document into PDF document
                PdfDocument _pdfDocument = _converter.ConvertToPDF(_wordDocument);
                _pdfDocument.Save(Application.StartupPath + "\\temp1\\document6.pdf");

                PDFFile _file =
                    PDFFile.Open(Application.StartupPath + "\\temp1\\document6.pdf");

                _file.SerialNumber = "PDFVW-Y11DV-6VYTH-TWHXK-6DRLB-7MNQB";

                for (int i = 0; i < _file.PageCount; i++)
                {
                    // Convert each page to bitmap and save it.
                    Bitmap pageImage = _file.GetPageImage(i, 96);
                    pageImage.Save(Application.StartupPath + "\\temp2\\document6" + i.ToString() + ".tif", ImageFormat.Tiff);
                    _listOfTifs.Add(Application.StartupPath + "\\temp2\\document6" + i.ToString() + ".tif");
                }

                _file.Dispose();
                _readFile.Close();
                _readFile.Dispose();
            }
            if (ckdocument7.Checked == true)
            {

                File.Copy(_document7Path, Application.StartupPath + "\\temp1\\document7.doc", true);

                Stream _readFile = new FileStream(Application.StartupPath + "\\temp1\\document7.doc", FileMode.Open, FileAccess.Read, FileShare.Read);
                WordDocument _wordDocument = new WordDocument(_readFile);
                DocToPDFConverter _converter = new DocToPDFConverter();
                //Convert word document into PDF document
                PdfDocument _pdfDocument = _converter.ConvertToPDF(_wordDocument);
                _pdfDocument.Save(Application.StartupPath + "\\temp1\\document7.pdf");

                PDFFile _file =
                    PDFFile.Open(Application.StartupPath + "\\temp1\\document7.pdf");

                _file.SerialNumber = "PDFVW-Y11DV-6VYTH-TWHXK-6DRLB-7MNQB";

                for (int i = 0; i < _file.PageCount; i++)
                {
                    // Convert each page to bitmap and save it.
                    Bitmap pageImage = _file.GetPageImage(i, 96);
                    pageImage.Save(Application.StartupPath + "\\temp2\\document7" + i.ToString() + ".tif", ImageFormat.Tiff);
                    _listOfTifs.Add(Application.StartupPath + "\\temp2\\document7" + i.ToString() + ".tif");
                }

                _file.Dispose();
                _readFile.Close();
                _readFile.Dispose();
            }
            if (ckdocument8.Checked == true)
            {

                File.Copy(_document8Path, Application.StartupPath + "\\temp1\\document8.doc", true);

                Stream _readFile = new FileStream(Application.StartupPath + "\\temp1\\document8.doc", FileMode.Open, FileAccess.Read, FileShare.Read);
                WordDocument _wordDocument = new WordDocument(_readFile);
                DocToPDFConverter _converter = new DocToPDFConverter();
                //Convert word document into PDF document
                PdfDocument _pdfDocument = _converter.ConvertToPDF(_wordDocument);
                _pdfDocument.Save(Application.StartupPath + "\\temp1\\document8.pdf");

                PDFFile _file =
                    PDFFile.Open(Application.StartupPath + "\\temp1\\document8.pdf");

                _file.SerialNumber = "PDFVW-Y11DV-6VYTH-TWHXK-6DRLB-7MNQB";

                for (int i = 0; i < _file.PageCount; i++)
                {
                    // Convert each page to bitmap and save it.
                    Bitmap pageImage = _file.GetPageImage(i, 96);
                    pageImage.Save(Application.StartupPath + "\\temp2\\document8" + i.ToString() + ".tif", ImageFormat.Tiff);
                    _listOfTifs.Add(Application.StartupPath + "\\temp2\\document8" + i.ToString() + ".tif");
                }

                _file.Dispose();
                _readFile.Close();
                _readFile.Dispose();
            }
            if (ckdocument9.Checked == true)
            {

                File.Copy(_document9Path, Application.StartupPath + "\\temp1\\document9.doc", true);

                Stream _readFile = new FileStream(Application.StartupPath + "\\temp1\\document9.doc", FileMode.Open, FileAccess.Read, FileShare.Read);
                WordDocument _wordDocument = new WordDocument(_readFile);
                DocToPDFConverter _converter = new DocToPDFConverter();
                //Convert word document into PDF document
                PdfDocument _pdfDocument = _converter.ConvertToPDF(_wordDocument);
                _pdfDocument.Save(Application.StartupPath + "\\temp1\\document9.pdf");

                PDFFile _file =
                    PDFFile.Open(Application.StartupPath + "\\temp1\\document9.pdf");

                _file.SerialNumber = "PDFVW-Y11DV-6VYTH-TWHXK-6DRLB-7MNQB";

                for (int i = 0; i < _file.PageCount; i++)
                {
                    // Convert each page to bitmap and save it.
                    Bitmap pageImage = _file.GetPageImage(i, 96);
                    pageImage.Save(Application.StartupPath + "\\temp2\\document9" + i.ToString() + ".tif", ImageFormat.Tiff);
                    _listOfTifs.Add(Application.StartupPath + "\\temp2\\document9" + i.ToString() + ".tif");
                }

                _file.Dispose();
                _readFile.Close();
                _readFile.Dispose();
            }
            if (ckdocument10.Checked == true)
            {

                File.Copy(_document10Path, Application.StartupPath + "\\temp1\\document10.doc", true);

                Stream _readFile = new FileStream(Application.StartupPath + "\\temp1\\document10.doc", FileMode.Open, FileAccess.Read, FileShare.Read);
                WordDocument _wordDocument = new WordDocument(_readFile);
                DocToPDFConverter _converter = new DocToPDFConverter();
                //Convert word document into PDF document
                PdfDocument _pdfDocument = _converter.ConvertToPDF(_wordDocument);
                _pdfDocument.Save(Application.StartupPath + "\\temp1\\document10.pdf");

                PDFFile _file =
                    PDFFile.Open(Application.StartupPath + "\\temp1\\document10.pdf");

                _file.SerialNumber = "PDFVW-Y11DV-6VYTH-TWHXK-6DRLB-7MNQB";

                for (int i = 0; i < _file.PageCount; i++)
                {
                    // Convert each page to bitmap and save it.
                    Bitmap pageImage = _file.GetPageImage(i, 96);
                    pageImage.Save(Application.StartupPath + "\\temp2\\document10" + i.ToString() + ".tif", ImageFormat.Tiff);
                    _listOfTifs.Add(Application.StartupPath + "\\temp2\\document10" + i.ToString() + ".tif");
                }

                _file.Dispose();
                _readFile.Close();
                _readFile.Dispose();
            }

            //util.ConvertToMultiPageTiff(_listOfTifs,_ftpfolder + "\\newtif.tif");
            util.ConvertToMultiPageTiff(_listOfTifs, Application.StartupPath + "\\temp2\\newtif.tif");

            try
            {
                File.Copy(Application.StartupPath + "\\temp2\\newtif.tif", "\\\\hmdn-notes.ct-ortho.com\\YHP-Notes\\" + _fileName + ".tif", true);

                UpdateAppointmentTable(_chargeSlipNumber);
            }
            catch (Exception er)
            {
                MessageBox.Show(er.Message,
                  "Problem Copying File", MessageBoxButtons.OK,
                  MessageBoxIcon.Exclamation);
            }

            try
            {
                KillWordForWindows();
            }
            catch { }


            MessageBox.Show("Files Moved",
              "Done", MessageBoxButtons.OK,
              MessageBoxIcon.Exclamation);

            Application.Exit();  
        }