Beispiel #1
0
        private void btnImportFile_Click(object sender, EventArgs e)
        {
            /******
             * How a CSV file works
             * > Rows are split by new lines
             * > Column data is then split by a comma
             *
             * Thus we need to read each line, split by a comma, then add the row
             */

            FormAdvanced _Owner = (FormAdvanced)Owner;
            DialogResult _DR    = MessageBox.Show("Do you want to overwrite existing GUIDs with these?\r\nClicking 'No' will import and not clear any existing GUIDs.", "Overwrite?", MessageBoxButtons.YesNo);

            if (_DR == DialogResult.Yes)
            {
                _Owner.btnClear_Click(null, null);
            }

            try
            {
                using (System.IO.StreamReader reader = new System.IO.StreamReader(this.ofdImport.OpenFile()))
                {
                    string s = string.Empty;
                    int    i = 0;

                    while (true)
                    {
                        s = reader.ReadLine();

                        //
                        // The last line will be null
                        //
                        if (s != null)
                        {
                            //
                            // This logic skips the first line if the chkIgnore box is checked
                            //
                            if (this.chkIgnore.Checked && i == 0)
                            {
                                ++i;
                                continue;
                            }

                            string[] GUID = s.Split(',');

                            if (GUID.Count() > 1)
                            {
                                if (GUID[0].Length >= 1 || GUID[1].Length >= 1)
                                {
                                    _Owner.updateLink(_Owner.dgvLinks.Rows.Add(new Object[] { GUID[0], GUID[1] }));
                                }
                                else
                                if (GUID[0].Length >= 1)
                                {
                                    _Owner.updateLink(_Owner.dgvLinks.Rows.Add(GUID[0]));
                                }
                            }
                        }
                        else
                        {
                            break;
                        }
                    }

                    MessageBox.Show("Import completed successfully.");
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(String.Format("An error was encountered while trying to import this file.\r\n{0}", ex.Message));
            }
        }
Beispiel #2
0
        //
        // Export list of links to the selected file
        //
        private void btnExport_Click(object sender, EventArgs e)
        {
            if (this.txtExportLocation.Text != string.Empty)
            {
                //
                // Check to see if this file exists first to see if we want to overwrite it
                //
                if (System.IO.File.Exists(this.ofdExport.FileName))
                {
                    DialogResult _DR = MessageBox.Show("This file already exists, do you want to overwrite it?", "File Exists", MessageBoxButtons.YesNo);

                    if (_DR != DialogResult.Yes)
                    {
                        return;
                    }
                }

                //
                // Build the string buffer for the content that we need to write to the file
                //
                string       buffer;
                FormAdvanced _Owner = (FormAdvanced)Owner;

                // Write header values to the buffer
                buffer = "Loan GUID,eSign Link";

                for (int i = 0; i < _Owner.dgvLinks.Rows.Count; ++i)
                {
                    // Skip row if there's no link generated
                    if (_Owner.getLink(i) == string.Empty)
                    {
                        continue;
                    }

                    buffer = String.Format("{0}\r\n{1},{2}", buffer, _Owner.getLoanGUID(i), _Owner.getLink(i));
                }

                //
                // Open a stream writer to the export path. This will create the file if it doesn't exist.
                //
                try
                {
                    using (System.IO.StreamWriter _writer = new System.IO.StreamWriter(this.ofdExport.FileName))
                    {
                        _writer.WriteLine(buffer);
                        _writer.Close();
                    }

                    MessageBox.Show("Exported successfully.");
                    this.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(String.Format("Unable to save export file due to an error.\r\n\r\n{0}", ex.Message));
                }
            }
            else
            {
                MessageBox.Show("No file export path has been selected.");
            }
        }
Beispiel #3
0
        private void btnTxtImport_Click(object sender, EventArgs e)
        {
            FormAdvanced _Owner = (FormAdvanced)Owner;
            DialogResult _DR    = MessageBox.Show("Do you want to overwrite existing GUIDs with these?\r\nClicking 'No' will import and not clear any existing GUIDs.", "Overwrite?", MessageBoxButtons.YesNo);

            if (_DR == DialogResult.Yes)
            {
                _Owner.btnClear_Click(null, null);
            }

            if (this.txtImport.Text != string.Empty)
            {
                if (this.rdbCSV.Checked)
                {
                    //
                    // Importing via CSV value
                    //
                    foreach (String GUID in this.txtImport.Text.Split(','))
                    {
                        if (GUID != String.Empty)
                        {
                            _Owner.dgvLinks.Rows.Add(GUID);
                        }
                    }

                    MessageBox.Show("Import completed successfully.");
                    this.Close();
                }
                else
                {
                    //
                    // Importing using line breaks
                    //
                    using (System.IO.StringReader Reader = new System.IO.StringReader(this.txtImport.Text))
                    {
                        while (true)
                        {
                            string s = Reader.ReadLine();

                            //
                            // The final line will be null
                            //
                            if (s != null)
                            {
                                _Owner.dgvLinks.Rows.Add(s);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                    MessageBox.Show("Import completed successfully.");
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("You are required to enter text to import using this method.");
            }
        }