コード例 #1
0
        //GETS TABLES FROM DB
        private void ExportToFile(List <string> DbTables, string filePath)
        {
            foreach (var table in DbTables)
            {
                string         connectionString = null;
                SqlConnection  connection;
                SqlCommand     command;
                DataSet        ds      = new DataSet();
                SqlDataAdapter adapter = new SqlDataAdapter();
                string         sql     = null;

                connectionString = Settings.Default.LocalDb;
                connection       = new SqlConnection(connectionString);

                //GET LIST OF TABLES
                sql = "Select * From " + table;

                try
                {
                    connection.Open();
                    command = new SqlCommand(sql, connection);
                    adapter.SelectCommand = command;
                    adapter.Fill(ds);
                    adapter.Dispose();
                    command.Dispose();
                    connection.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Could Not Download " + table + " Table!!", @"CEMS Study", MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                }

                fileExportFunctionByTable(ds, table, filePath);
            }

            MessageBox.Show(@"DB Table Files Downloaded to " + filePath, @"CEMS Study", MessageBoxButtons.OK,
                            MessageBoxIcon.Information);

            //OPENS FOLDERS WHERE FILES ARE SAVED
            var psi = new ProcessStartInfo();

            psi.FileName  = @"c:\windows\system32\explorer.exe";
            psi.Arguments = filePath;
            Process.Start(psi);


            Hide();
            PasswordsLogin pl = new PasswordsLogin();

            pl.Show();
        }
コード例 #2
0
        private void buttonExport_Click(object sender, EventArgs e)
        {
            var answer = MessageBox.Show("Export Database??", "CEMS Study", MessageBoxButtons.OKCancel,
                                         MessageBoxIcon.Question);

            //EXPORT
            if (answer == DialogResult.OK)
            {
                string         connectionString = null;
                SqlConnection  connection;
                SqlCommand     command;
                DataSet        ds      = new DataSet();
                SqlDataAdapter adapter = new SqlDataAdapter();
                string         sql     = null;

                connectionString = Settings.Default.LocalDb;
                connection       = new SqlConnection(connectionString);

                //GET LIST OF TABLES
                sql = "Select * From sys.Tables";

                try
                {
                    connection.Open();
                    command = new SqlCommand(sql, connection);
                    adapter.SelectCommand = command;
                    adapter.Fill(ds);
                    adapter.Dispose();
                    command.Dispose();
                    connection.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

                var DbTables = new List <string>();


                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DbTables.Add(ds.Tables[0].Rows[i].ItemArray[0].ToString());
                }

                //WHERE TO SAVE
                FolderBrowserDialog fbd = new FolderBrowserDialog();
                fbd.ShowDialog();
                var filePath = "";

                if (fbd.ShowDialog() == DialogResult.OK)
                {
                    filePath = fbd.SelectedPath;
                }
                else
                {
                    filePath = string.Empty;
                    MessageBox.Show("No Path Selected. Aborting Process", "CEMS Study", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }

                ExportToFile(DbTables, filePath);
            }
            else
            {
                Hide();
                var pw = new PasswordsLogin();
                pw.Show();
            }
        }
コード例 #3
0
        private void textBoxPassword_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Enter)
            {
                var            password = "******";
                PasswordsLogin pw       = new PasswordsLogin();

                if (textBoxPassword.Text != password)
                {
                    MessageBox.Show("Incorrect Password!!", "CEMS Study", MessageBoxButtons.OK,
                                    MessageBoxIcon.Exclamation);
                    Hide();
                    //var pl = new PasswordsLogin();
                    //pl.Show();
                    return;
                }

                //USER WANTS TO EDIT DB AFTER ENTERING PASSWORD
                var openDb = MessageBox.Show("Edit Database?", "CEMS Study", MessageBoxButtons.YesNo,
                                             MessageBoxIcon.Question);

                if (openDb == DialogResult.Yes)
                {
                    Hide();
                    pw.Hide();
                    var export = new ExportDb();
                    export.Show();
                    export.TopMost = true;

                    return;
                }


                //USER WANTS TO EDIT DB AFTER ENTERING PASSWORD
                var openHyperlink = MessageBox.Show("Remove PDF Hyperlinks?", "CEMS Study", MessageBoxButtons.YesNo,
                                                    MessageBoxIcon.Question);

                if (openHyperlink == DialogResult.Yes)
                {
                    Hide();
                    pw.Hide();
                    var rpl = new RemovePdfLinks();
                    rpl.Show();
                    rpl.TopMost = true;
                    return;
                }

                //ADD ACRONYMS
                var openAcronyms = MessageBox.Show("Add Acronyms?", "CEMS Study", MessageBoxButtons.YesNo,
                                                   MessageBoxIcon.Question);

                if (openAcronyms == DialogResult.Yes)
                {
                    Hide();
                    pw.Hide();
                    var rpl = new AddAcronyms();
                    rpl.Show();
                    rpl.TopMost = true;
                    return;
                }


                //ADD DEFINITIONS
                var openDefinitions = MessageBox.Show("Add Definitions", "CEMS Study", MessageBoxButtons.YesNo,
                                                      MessageBoxIcon.Question);

                if (openDefinitions == DialogResult.Yes)
                {
                    Hide();
                    pw.Hide();
                    var rpl = new AddDefinitions();
                    rpl.Show();
                    rpl.TopMost = true;
                    return;
                }


                //ADD UNITS OF MEASURE
                var openUoM = MessageBox.Show("Add Units of Measure?", "CEMS Study", MessageBoxButtons.YesNo,
                                              MessageBoxIcon.Question);

                if (openUoM == DialogResult.Yes)
                {
                    Hide();
                    pw.Hide();
                    var rpl = new AddUnitsofMeasure();
                    rpl.Show();
                    rpl.TopMost = true;
                    return;
                }

                //DEFAULTS BACK TO PASSWORD SCREEN
                Hide();
                PasswordsLogin passwordsLoginl = new PasswordsLogin();
                passwordsLoginl.Hide();
            }
        }