コード例 #1
0
        private void bt_entrar_Click(object sender, EventArgs e)
        {
            this.Close();
            //frm_dashboard dash = new frm_dashboard();
            //dash.Show();

            frm_main control = new frm_main();

            String        form = "frm_dashboard";
            frm_dashboard db   = new frm_dashboard();

            if (control.formAberto(form))
            {
                Application.OpenForms[form].BringToFront();
            }
            else
            {
                //control.abrirForm(db, frm_main.opened);
            }
        }
コード例 #2
0
        public void montarResultado(string query, DataGridView dgv)
        {
            // INSTANCIANDO UMA NOVA CONEXAO
            SqlConnection conn = Conexao.obterConexao();

            try
            {
                SqlCommand    retorno = new SqlCommand(query, conn);
                SqlDataReader row     = retorno.ExecuteReader();

                // CRIANDO UM  E POPULANDO UM DATATABLE COM O RETORNO DA QUERY
                DataTable tabela = new DataTable();
                tabela.Load(row);

                // CONTANDO O TOTAL DE LINHAS DO RETORNO PARA O VALOR MAXIMO DA PROGRESSBAR
                int rows = tabela.Rows.Count;


                // LAÇO DA TABELA
                using (SqlDataReader DR = retorno.ExecuteReader())
                {
                    dgv.Columns.Clear();
                    dgv.Rows.Clear();
                    // SE A CONSULTA RETORNAR LINHAS
                    if (DR.HasRows)
                    {
                        frm_main form = new frm_main();
                        // Get field information.
                        DataTable schema    = DR.GetSchemaTable();
                        int       field_num = 0;
                        foreach (DataRow schema_row in schema.Rows)
                        {
                            // Create the column.
                            int col_num = dgv.Columns.Add(field_num.ToString(), schema_row.Field <string>("ColumnName"));

                            field_num++;

                            // Make the column size to fit its data.
                            dgv.Columns[col_num].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                        }

                        // Make room to hold a row's values.
                        object[] values = new object[DR.FieldCount];

                        // Loop while the reader has unread data.
                        while (DR.Read())
                        {
                            // Add this row to the DataGridView.
                            DR.GetValues(values);
                            dgv.Rows.Add(values);
                        }

                        // ENQUANTO HOUVER LEITURA NAS LINHAS DO RETORNO

                        /*while (DR.Read())
                         * {
                         *
                         *
                         *  //tabela.Columns.Add(DR[""].ToString, typeof(String));
                         *  // LAÇO PARA LER AS COLUNAS DA LINHA
                         *  for (int i = 0; i < DR.FieldCount; i++)
                         *  {
                         *
                         *      MessageBox.Show(DR[i] + "\t", "");
                         *  }
                         *
                         * }*/
                    }
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show("Erro ao exportar o arquivo  \n\nDetalhe do erro: " + ex.Message);
            }
        }