Пример #1
0
        public void loadDataGridView()
        {
            String query = "SELECT * FROM SONIC_QUERY";

            conn = Conexao.obterConexao();

            SqlCommand    retorno = new SqlCommand(query, conn);
            SqlDataReader row     = retorno.ExecuteReader();
            DataTable     lista   = new DataTable();

            lista.Load(row);
            //dgv_query.DataSource = lista;
            //if (dgv_query.Rows.Count > 0) {
            //    dgv_query.Rows[0].Selected = true;
            //}
            //dgv_query.DefaultCellStyle.SelectionBackColor = Color.PaleGreen;
            //dgv_query.DefaultCellStyle.SelectionForeColor = Color.Black;
            //DataGridViewColumn c = dgv_query.Columns[0];
            //DataGridViewColumn d = dgv_query.Columns[3];
            //DataGridViewColumn e = dgv_query.Columns[4];
            // d.ReadOnly = false;
            //e.ReadOnly = false;
            //c.Width = 30;
            //d.Width = 50;
            //e.Width = 50;


            //for (int i = 0; i < dgv_query.Columns.Count; i++)
            // {

            //   dgv_query.Columns[i].HeaderText = Util.FirstCharToUpper(dgv_query.Columns[i].Name.Replace("_", " "));
            //dgv_query.Columns[i].ReadOnly = false;

            //}
        }
Пример #2
0
        public void loadComBoList()
        {
            //tb_secao.CharacterCasing = CharacterCasing.Upper;
            conn = Conexao.obterConexao();
            List <string> tables = new List <string>();
            DataTable     dt     = conn.GetSchema("Views");

            ArrayList     valuesList = new ArrayList();
            SqlCommand    command    = new SqlCommand("SELECT SECAO FROM SONIC_QUERY ORDER BY id", conn);
            SqlDataReader dataReader = command.ExecuteReader();
            int           count      = 0;

            while (dataReader.Read())
            {
                valuesList.Add(dataReader[0].ToString());
                //MessageBox.Show(valuesList[count].ToString());
                count += 1;
            }
            conn.Close();
            int count2 = 0;

            foreach (DataRow rowTables in dt.Rows)
            {
                string tablename = (string)rowTables[2];

                if (!valuesList.Contains(tablename.ToString()))
                {
                    //cb_view.Items.Add(tablename);
                }


                count2 += 1;
            }
        }
Пример #3
0
        public void loadGridView()
        {
            conn = Conexao.obterConexao();

            String query = "SELECT SU.CODIGO_USUARIO, SU.NOME FROM SONIC_USUARIOS SU GROUP BY SU.CODIGO_USUARIO, SU.NOME ";

            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);

            dgv_usuario.DataSource = tabela;
            //dgv_usuario.MultiSelect = false;
            dgv_usuario.DefaultCellStyle.SelectionBackColor = Color.PaleGreen;
            dgv_usuario.DefaultCellStyle.SelectionForeColor = Color.Black;
            dgv_usuario.Rows[0].Selected = true;
            DataGridViewColumn c = dgv_usuario.Columns[0];

            c.Width = 60;
            Conexao.fecharConexao();
        }
Пример #4
0
        private void loadExampleList(Boolean site)
        {
            //Task.Run(() => GetDetailsForFileById(site));

            DataGridView common;
            String       query = String.Empty;
            PictureBox   pb    = null;

            if (site)
            {
                query  = rtb_site_query.Text.Replace("*", "TOP 5 * ").Replace("WHERE CODIGO_USUARIO = ?", "");
                common = dgv_site_exemplo;
                pb     = pb_site_progress;
            }
            else
            {
                query  = rtb_usuarios_query.Text.Replace("*", "TOP 5 * ").Replace("WHERE CODIGO_USUARIO = ?", "");
                common = dgv_usuarios_exemplo;
                pb     = pb_usuarios_progress;
            }

            conn = Conexao.obterConexao();
            SqlCommand    retorno = new SqlCommand(query, conn);
            SqlDataReader row     = null;

            try
            {
                row = retorno.ExecuteReader();
                DataTable lista = new DataTable();
                if (row.HasRows)
                {
                    lista.Load(row);
                    common.ReadOnly = true;
                    pb.Visible      = false;
                }
                common.AdvancedCellBorderStyle.All = DataGridViewAdvancedCellBorderStyle.None;
                common.AllowUserToAddRows          = false;
                common.DataSource = lista;
                //common.ColumnHeadersVisible = false;
                //common.RowHeadersVisible = false;
                //common.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
                common.AllowUserToResizeRows = false;
                common.DefaultCellStyle.SelectionBackColor = Color.PaleGreen;
                common.DefaultCellStyle.SelectionForeColor = Color.Black;
            }
            catch (SqlException ex)
            {
                common.DataSource = null;
                common.Refresh();
                pb.Visible = false;
                MessageBox.Show(ex.Message);
            }
        }
Пример #5
0
        public async Task GetDetailsForFileById(Boolean site)
        {
            DataTable    lista = new DataTable();
            SqlCommand   retorno;
            DataGridView common;

            conn = Conexao.obterConexao();
            String     query = String.Empty;
            PictureBox pb    = null;

            if (site)
            {
                query  = rtb_site_query.Text;
                common = dgv_site_exemplo;
                pb     = pb_site_progress;
            }
            else
            {
                query  = rtb_usuarios_query.Text.Replace("*", "TOP 1 * ");
                common = dgv_site_exemplo;
                pb     = pb_site_progress;
            }

            using (conn)
            {
                using (retorno = new SqlCommand(query, conn))
                {
                    retorno.CommandType = CommandType.Text;

                    //retorno.Parameters.AddWithValue("Id", id);

                    await conn.OpenAsync();

                    using (var reader = await retorno.ExecuteReaderAsync())
                    {
                        if (await reader.ReadAsync())
                        {
                            pb.Visible = false;
                            lista.Load(reader);
                            common.AdvancedCellBorderStyle.All = DataGridViewAdvancedCellBorderStyle.None;
                            common.AllowUserToAddRows          = false;
                            common.DataSource = lista;
                            //common.ColumnHeadersVisible = false;
                            //common.RowHeadersVisible = false;
                            //common.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
                            common.AllowUserToResizeRows = false;
                            common.DefaultCellStyle.SelectionBackColor = Color.PaleGreen;
                            common.DefaultCellStyle.SelectionForeColor = Color.Black;
                        }
                    }
                }
            }
        }
Пример #6
0
 void bgw_DoWork(object sender, DoWorkEventArgs e)
 {
     try {
         conn = Conexao.obterConexao();
         SqlCommand    retorno = new SqlCommand(query, conn);
         SqlDataReader row     = retorno.ExecuteReader();
         tabela = new DataTable();
         tabela.Load(row);
     }
     catch (SqlException ex) {
         MessageBox.Show(ex.Message);
     }
 }
Пример #7
0
 private void dgv_usuarios_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     dgv_usuarios.Rows[e.RowIndex].Selected = true;
     tsb_usuarios_salvar.Enabled            = false;
     rtb_usuarios_query.Enabled             = false;
     if (e.ColumnIndex == 0)
     {
         conn = Conexao.obterConexao();
         dgv_usuarios_exemplo.DataSource = null;
         dgv_usuarios_exemplo.Refresh();
         rtb_usuarios_query.Text = "";
         SqlCommand cmd = new SqlCommand("SELECT query FROM SONIC_SECAO_USUARIOS WHERE secao = '" + dgv_usuarios.CurrentCell.Value.ToString() + "'", conn);
         rtb_usuarios_query.Text = cmd.ExecuteScalar().ToString();
     }
 }
Пример #8
0
        public static bool validarConexao()
        {
            bool connected = false;

            // SOLICITAR CONEXAO USANDO A CLASSE DE CONEXAO
            SqlConnection conn = Conexao.obterConexao();

            if (conn == null && conn.State != ConnectionState.Closed)
            {
                // PODEMOS ABRIR UM MESSAGEBOX PARA UM FEEDBACK DA CONEXAO
                //MessageBox.Show("Conexao não ok", "");
            }
            else
            {
                // COMO É APENAS UM TESTE, PODEMOS FECHAR A CONEXAO
                connected = true;
                Conexao.fecharConexao();
            }
            return(connected);
        }
Пример #9
0
        public void gerarConsulta(System.IO.DirectoryInfo arquivos, String nome, DataGridView dgv)
        {
            // STRING QUE RECEBE O DIRETÓRIO
            string diretorio = Properties.Settings.Default.RECEBIDOS + "\\";

            // INSTANCIANDO UMA NOVA CONEXAO
            SqlConnection conn = Conexao.obterConexao();

            // OBTENDO OS ARQUIVOS PARA MONTAR QUERY
            FileInfo[] file = arquivos.GetFiles(nome + ".TXT");
            foreach (System.IO.FileInfo fileinfo in file)
            {
                // CAPTURANDO O ARQUVIO
                string query   = string.Empty;
                string arquivo = fileinfo.ToString();

                // LENDO O ARQUIVO
                System.IO.StreamReader sr = new System.IO.StreamReader(diretorio + arquivo);
                string line = sr.ReadLine();

                // LAÇO PA CONCATENAR AS LINHAS E MONTAR A QUERY
                while (line != null)
                {
                    query += line;
                    line   = sr.ReadLine();
                }
                //String query2 = "SELECT * FROM ST_VENDEDORES";
                // AQUI DECIDE O QUE FAZER COM A QUERY GERADA
                //GravarTXT(conn, arquivo, query);
                //montarResultado(conn, arquivo, query2, dgv);
                // FECHANDO O OBJETO STREAMREADER
                sr.Close();
            }

            // FECHANDO A CONEXAO COM O BANCO
            Conexao.fecharConexao(conn);
        }
Пример #10
0
        private void tsb_usuarios_excluir_Click(object sender, EventArgs e)
        {
            if (dgv_usuarios.SelectedRows.Count > 0)
            {
                DialogResult res = MessageBox.Show("Deseja excluir o(s) registro(s)?", "Excluir", MessageBoxButtons.OKCancel);
                if (res == DialogResult.OK)
                {
                    try
                    {
                        String secao = String.Empty;
                        String query = String.Empty;
                        conn = Conexao.obterConexao();

                        foreach (DataGridViewRow r in dgv_usuarios.SelectedRows)
                        {
                            secao = r.Cells[0].Value.ToString();
                            query = "DELETE FROM SONIC_SECAO_USUARIOS WHERE secao = '" + r.Cells[0].Value.ToString() + "'";
                            SqlCommand com = new SqlCommand(query, conn);
                            com.ExecuteNonQuery();
                        }
                    }
                    catch (SqlException ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    finally
                    {
                        conn.Close();
                        loadUserList();
                    }
                }
            }
            else
            {
                MessageBox.Show("Por favor, selecione uma linha.", "Aviso");
            }
        }
Пример #11
0
        // TESTAR A CONEXAO COM OS DADOS JA GRAVADOS
        public bool ConexaoLoad()
        {
            bool connected = false;
            // CARREGAR OS DADOS DE STATUS DA CONEXÃO NA TELA PRINCIPAL
            //gt_lbl_main_servidor_endereco.Text = Properties.Settings.Default.IP + "," +
            //Properties.Settings.Default.PORT;
            //gt_lbl_main_servidor_database.Text = Properties.Settings.Default.DATABASE;

            // SOLICITAR CONEXAO USANDO A CLASSE DE CONEXAO
            SqlConnection conn = Conexao.obterConexao();

            if (conn == null)
            {
                // PODEMOS ABRIR UM MESSAGEBOX PARA UM FEEDBACK DA CONEXAO
                //MessageBox.Show("Conexao não ok", "");
            }
            else
            {
                // COMO É APENAS UM TESTE, PODEMOS FECHAR A CONEXAO
                connected = true;
                Conexao.fecharConexao(conn);
            }
            return(connected);
        }
Пример #12
0
        public void loadComBoList()
        {
            //tb_secao.CharacterCasing = CharacterCasing.Upper;
            conn = Conexao.obterConexao();
            List <string> tables = new List <string>();
            DataTable     dt     = conn.GetSchema("Views");

            ArrayList     valuesList = new ArrayList();
            SqlCommand    com1       = new SqlCommand("SELECT nome_view FROM SONIC_SECAO_SITE UNION SELECT nome_view FROM SONIC_SECAO_USUARIOS", conn);
            SqlDataReader dataReader = com1.ExecuteReader();
            int           count      = 0;

            while (dataReader.Read())
            {
                valuesList.Add(dataReader[0].ToString());
                //MessageBox.Show(valuesList[count].ToString());
                count += 1;
            }

            conn.Close();
            int count2 = 0;

            cb_secao.IntegralHeight   = false;
            cb_secao.MaxDropDownItems = 8;
            foreach (DataRow rowTables in dt.Rows)
            {
                string tablename = (string)rowTables[2];

                if (!valuesList.Contains(tablename.ToString()))
                {
                    cb_secao.Items.Add(tablename);
                }

                count2 += 1;
            }
        }
Пример #13
0
        public void loadSiteList()
        {
            String query = "SELECT secao FROM SONIC_SECAO_SITE ORDER BY id";

            conn = Conexao.obterConexao();

            SqlCommand    retorno = new SqlCommand(query, conn);
            SqlDataReader row     = retorno.ExecuteReader();
            DataTable     lista   = new DataTable();

            if (row.HasRows)
            {
                lista.Load(row);
                dgv_site.ReadOnly = true;
            }
            dgv_site.AdvancedCellBorderStyle.All = DataGridViewAdvancedCellBorderStyle.None;
            dgv_site.AllowUserToAddRows          = false;
            dgv_site.DataSource            = lista;
            dgv_site.ColumnHeadersVisible  = false;
            dgv_site.RowHeadersVisible     = false;
            dgv_site.AutoSizeColumnsMode   = DataGridViewAutoSizeColumnsMode.Fill;
            dgv_site.AllowUserToResizeRows = false;

            dgv_site.DefaultCellStyle.SelectionBackColor = Color.PaleGreen;
            dgv_site.DefaultCellStyle.SelectionForeColor = Color.Black;
            if (dgv_site.Rows.Count > 0)
            {
                dgv_site.Rows[0].Selected = true;
                SqlCommand cmd = new SqlCommand("SELECT TOP 5 query FROM SONIC_SECAO_SITE ORDER BY id", conn);
                rtb_site_query.Text = cmd.ExecuteScalar().ToString();
            }
            else
            {
                rtb_site_query.Text = "";
            }
        }
Пример #14
0
        private void fillDashInfo()
        {
            String query_rec_today       = "SELECT * FROM ST_PED_DAY";
            String query_rec_week        = "SELECT * FROM ST_PED_WEEK";
            String query_rec_month       = "SELECT * FROM ST_PED_MONTH";
            String query_rec_last_month  = "SELECT * FROM ST_PED_LAST_MONTH";
            String query_proc_today      = "SELECT * FROM ST_CLI_DAY";
            String query_proc_week       = "SELECT * FROM ST_CLI_WEEK";
            String query_proc_month      = "SELECT * FROM ST_CLI_MONTH";
            String query_proc_last_month = "SELECT * FROM ST_CLI_LAST_MONTH";

            Int32 int_rec_today       = 0;
            Int32 int_rec_week        = 0;
            Int32 int_rec_month       = 0;
            Int32 int_rec_last_month  = 0;
            Int32 int_proc_today      = 0;
            Int32 int_proc_week       = 0;
            Int32 int_proc_month      = 0;
            Int32 int_proc_last_month = 0;

            SqlConnection conn = null;

            try
            {
                conn = Conexao.obterConexao();
            }
            catch (SqlException e)
            {
                MessageBox.Show("Aparentemente não há conexão com banco de dados.\n\nDetalhe do erro: " + e.Message, "Erro.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                //pn_ped_today.Invoke(new Action(() => pb_ped.Visible = false));
                //pn_cli_today.Invoke(new Action(() => pb_cli.Visible = false));
            }


            if (conn != null || conn.State != ConnectionState.Closed)
            {
                try
                {
                    SqlCommand retorno1 = new SqlCommand(query_rec_today, conn);
                    int_rec_today = (Int32)retorno1.ExecuteScalar();
                    SqlCommand retorno2 = new SqlCommand(query_rec_week, conn);
                    int_rec_week = (Int32)retorno2.ExecuteScalar();
                    SqlCommand retorno3 = new SqlCommand(query_rec_month, conn);
                    int_rec_month = (Int32)retorno3.ExecuteScalar();
                    SqlCommand retorno4 = new SqlCommand(query_rec_last_month, conn);
                    int_rec_last_month = (Int32)retorno4.ExecuteScalar();
                    SqlCommand retorno5 = new SqlCommand(query_proc_today, conn);
                    int_proc_today = (Int32)retorno5.ExecuteScalar();
                    SqlCommand retorno6 = new SqlCommand(query_proc_week, conn);
                    int_proc_week = (Int32)retorno6.ExecuteScalar();
                    SqlCommand retorno7 = new SqlCommand(query_proc_month, conn);
                    int_proc_month = (Int32)retorno7.ExecuteScalar();
                    SqlCommand retorno8 = new SqlCommand(query_proc_last_month, conn);
                    int_proc_last_month = (Int32)retorno8.ExecuteScalar();

                    Panel rec_today = new Panel();
                    rec_today.Size      = new System.Drawing.Size((pnl_rec.Width / 4) - 5, 88);
                    rec_today.BackColor = Color.FromArgb(153, 180, 209);
                    rec_today.Location  = new Point(5, 32);
                    Label lb_rec_today = new Label();
                    lb_rec_today.AutoSize  = true;
                    lb_rec_today.Location  = new Point(3, 3);
                    lb_rec_today.Text      = "HOJE";
                    lb_rec_today.ForeColor = Color.White;
                    lb_rec_today.Font      = new Font("Arial", 10, FontStyle.Bold);
                    Label lb_rec_t_value = new Label();
                    lb_rec_t_value.Location    = new Point(5, rec_today.Height / 4);
                    lb_rec_t_value.Text        = int_rec_today.ToString();
                    lb_rec_t_value.MinimumSize = new System.Drawing.Size(rec_today.Width - 10, (rec_today.Height) - (rec_today.Height / 3));
                    if (int_rec_today.ToString().Length < 4)
                    {
                        lb_rec_t_value.Font = new Font("Arial", rec_today.Height / 2, FontStyle.Regular);
                    }
                    else
                    {
                        lb_rec_t_value.Font = new Font("Arial", rec_today.Height / 3, FontStyle.Regular);
                    }
                    lb_rec_t_value.TextAlign = ContentAlignment.MiddleCenter;
                    //lb_t_value.BackColor = Color.Green;
                    lb_rec_t_value.ForeColor = Color.White;
                    rec_today.Controls.Add(lb_rec_today);
                    rec_today.Controls.Add(lb_rec_t_value);


                    Panel rec_week = new Panel();
                    rec_week.Size      = new System.Drawing.Size((pnl_cli.Width / 4) - 5, 88);
                    rec_week.BackColor = Color.FromArgb(153, 180, 209);
                    rec_week.Location  = new Point(rec_today.Width + 10, 32);
                    Label lb_rec_week = new Label();
                    lb_rec_week.AutoSize  = true;
                    lb_rec_week.Location  = new Point(3, 3);
                    lb_rec_week.Text      = "ESSA SEMANA";
                    lb_rec_week.ForeColor = Color.White;
                    lb_rec_week.Font      = new Font("Arial", 10, FontStyle.Bold);
                    Label lb_rec_w_value = new Label();
                    lb_rec_w_value.Location    = new Point(5, rec_week.Height / 4);
                    lb_rec_w_value.Text        = int_rec_week.ToString();
                    lb_rec_w_value.MinimumSize = new System.Drawing.Size(rec_week.Width - 10, (rec_week.Height) - (rec_week.Height / 3));
                    if (int_rec_week.ToString().Length < 4)
                    {
                        lb_rec_w_value.Font = new Font("Arial", rec_week.Height / 2, FontStyle.Regular);
                    }
                    else
                    {
                        lb_rec_w_value.Font = new Font("Arial", rec_week.Height / 3, FontStyle.Regular);
                    }
                    lb_rec_w_value.TextAlign = ContentAlignment.MiddleCenter;
                    //lb_t_value.BackColor = Color.Green;
                    lb_rec_w_value.ForeColor = Color.White;
                    rec_week.Controls.Add(lb_rec_week);
                    rec_week.Controls.Add(lb_rec_w_value);

                    Panel rec_month = new Panel();
                    rec_month.Size      = new System.Drawing.Size((pnl_cli.Width / 4) - 5, 88);
                    rec_month.BackColor = Color.FromArgb(153, 180, 209);
                    rec_month.Location  = new Point(rec_today.Width + rec_week.Width + 15, 32);
                    Label lb_rec_month = new Label();
                    lb_rec_month.AutoSize  = true;
                    lb_rec_month.Location  = new Point(3, 3);
                    lb_rec_month.Text      = "MÊS ATUAL";
                    lb_rec_month.ForeColor = Color.White;
                    lb_rec_month.Font      = new Font("Arial", 10, FontStyle.Bold);
                    Label lb_rec_m_value = new Label();
                    lb_rec_m_value.Location    = new Point(5, rec_month.Height / 4);
                    lb_rec_m_value.Text        = int_rec_month.ToString();
                    lb_rec_m_value.MinimumSize = new System.Drawing.Size(rec_month.Width - 10, (rec_month.Height) - (rec_month.Height / 3));
                    if (int_rec_month.ToString().Length < 4)
                    {
                        lb_rec_m_value.Font = new Font("Arial", rec_month.Height / 2, FontStyle.Regular);
                    }
                    else
                    {
                        lb_rec_m_value.Font = new Font("Arial", rec_month.Height / 3, FontStyle.Regular);
                    }
                    lb_rec_m_value.TextAlign = ContentAlignment.MiddleCenter;
                    //lb_rec_m_value.BackColor = Color.Green;
                    lb_rec_m_value.ForeColor = Color.White;
                    rec_month.Controls.Add(lb_rec_month);
                    rec_month.Controls.Add(lb_rec_m_value);

                    Panel rec_last_month = new Panel();
                    rec_last_month.Size      = new System.Drawing.Size((pnl_cli.Width / 4) - 6, 88);
                    rec_last_month.BackColor = Color.FromArgb(153, 180, 209);
                    rec_last_month.Location  = new Point(rec_today.Width + rec_week.Width + rec_month.Width + 20, 32);
                    Label lb_rec_last_month = new Label();
                    lb_rec_last_month.AutoSize  = true;
                    lb_rec_last_month.Location  = new Point(3, 3);
                    lb_rec_last_month.Text      = "MÊS ANTERIOR";
                    lb_rec_last_month.ForeColor = Color.White;
                    lb_rec_last_month.Font      = new Font("Arial", 10, FontStyle.Bold);
                    Label lb_rec_lm_value = new Label();
                    lb_rec_lm_value.Location    = new Point(5, rec_last_month.Height / 4);
                    lb_rec_lm_value.Text        = int_rec_last_month.ToString();
                    lb_rec_lm_value.MinimumSize = new System.Drawing.Size(rec_last_month.Width - 10, (rec_last_month.Height) - (rec_last_month.Height / 3));
                    if (int_rec_last_month.ToString().Length < 4)
                    {
                        lb_rec_lm_value.Font = new Font("Arial", rec_last_month.Height / 2, FontStyle.Regular);
                    }
                    else
                    {
                        lb_rec_lm_value.Font = new Font("Arial", rec_last_month.Height / 3, FontStyle.Regular);
                    }
                    lb_rec_lm_value.TextAlign = ContentAlignment.MiddleCenter;
                    //lb_t_value.BackColor = Color.Green;
                    lb_rec_lm_value.ForeColor = Color.White;
                    rec_last_month.Controls.Add(lb_rec_last_month);
                    rec_last_month.Controls.Add(lb_rec_lm_value);

                    Panel proc_today = new Panel();
                    proc_today.Size      = new System.Drawing.Size((pnl_cli.Width / 4) - 5, 88);
                    proc_today.BackColor = Color.FromArgb(153, 180, 209);
                    proc_today.Location  = new Point(5, 32);
                    Label lb_proc_today = new Label();
                    lb_proc_today.AutoSize  = true;
                    lb_proc_today.Location  = new Point(3, 3);
                    lb_proc_today.Text      = "HOJE";
                    lb_proc_today.ForeColor = Color.White;
                    lb_proc_today.Font      = new Font("Arial", 10, FontStyle.Bold);
                    Label lb_proc_t_value = new Label();
                    lb_proc_t_value.Location    = new Point(5, proc_today.Height / 4);
                    lb_proc_t_value.Text        = int_proc_today.ToString();
                    lb_proc_t_value.MinimumSize = new System.Drawing.Size(proc_today.Width - 10, (proc_today.Height) - (proc_today.Height / 3));
                    if (int_proc_today.ToString().Length < 4)
                    {
                        lb_proc_t_value.Font = new Font("Arial", proc_today.Height / 2, FontStyle.Regular);
                    }
                    else
                    {
                        lb_proc_t_value.Font = new Font("Arial", proc_today.Height / 3, FontStyle.Regular);
                    }
                    lb_proc_t_value.TextAlign = ContentAlignment.MiddleCenter;
                    //lb_t_value.BackColor = Color.Green;
                    lb_proc_t_value.ForeColor = Color.White;
                    proc_today.Controls.Add(lb_proc_today);
                    proc_today.Controls.Add(lb_proc_t_value);


                    Panel proc_week = new Panel();
                    proc_week.Size      = new System.Drawing.Size((pnl_cli.Width / 4) - 5, 88);
                    proc_week.BackColor = Color.FromArgb(153, 180, 209);
                    proc_week.Location  = new Point(proc_today.Width + 10, 32);
                    Label lb_proc_week = new Label();
                    lb_proc_week.AutoSize  = true;
                    lb_proc_week.Location  = new Point(3, 3);
                    lb_proc_week.Text      = "ESSA SEMANA";
                    lb_proc_week.ForeColor = Color.White;
                    lb_proc_week.Font      = new Font("Arial", 10, FontStyle.Bold);
                    Label lb_proc_w_value = new Label();
                    lb_proc_w_value.Location    = new Point(5, proc_week.Height / 4);
                    lb_proc_w_value.Text        = int_proc_week.ToString();
                    lb_proc_w_value.MinimumSize = new System.Drawing.Size(proc_week.Width - 10, (proc_week.Height) - (proc_week.Height / 3));
                    if (int_proc_week.ToString().Length < 4)
                    {
                        lb_proc_w_value.Font = new Font("Arial", proc_week.Height / 2, FontStyle.Regular);
                    }
                    else
                    {
                        lb_proc_w_value.Font = new Font("Arial", proc_week.Height / 3, FontStyle.Regular);
                    }
                    lb_proc_w_value.TextAlign = ContentAlignment.MiddleCenter;
                    //lb_t_value.BackColor = Color.Green;
                    lb_proc_w_value.ForeColor = Color.White;
                    proc_week.Controls.Add(lb_proc_week);
                    proc_week.Controls.Add(lb_proc_w_value);

                    Panel proc_month = new Panel();
                    proc_month.Size      = new System.Drawing.Size((pnl_cli.Width / 4) - 5, 88);
                    proc_month.BackColor = Color.FromArgb(153, 180, 209);
                    proc_month.Location  = new Point(proc_today.Width + proc_week.Width + 15, 32);
                    Label lb_proc_month = new Label();
                    lb_proc_month.AutoSize  = true;
                    lb_proc_month.Location  = new Point(3, 3);
                    lb_proc_month.Text      = "MÊS ATUAL";
                    lb_proc_month.ForeColor = Color.White;
                    lb_proc_month.Font      = new Font("Arial", 10, FontStyle.Bold);
                    Label lb_proc_m_value = new Label();
                    lb_proc_m_value.Location    = new Point(5, proc_month.Height / 4);
                    lb_proc_m_value.Text        = int_proc_month.ToString();
                    lb_proc_m_value.MinimumSize = new System.Drawing.Size(proc_month.Width - 10, (proc_month.Height) - (proc_month.Height / 3));
                    if (int_proc_month.ToString().Length < 4)
                    {
                        lb_proc_m_value.Font = new Font("Arial", proc_month.Height / 2, FontStyle.Regular);
                    }
                    else
                    {
                        lb_proc_m_value.Font = new Font("Arial", proc_month.Height / 3, FontStyle.Regular);
                    }
                    lb_proc_m_value.TextAlign = ContentAlignment.MiddleCenter;
                    //lb_t_value.BackColor = Color.Green;
                    lb_proc_m_value.ForeColor = Color.White;
                    proc_month.Controls.Add(lb_proc_month);
                    proc_month.Controls.Add(lb_proc_m_value);

                    Panel proc_last_month = new Panel();
                    proc_last_month.Size      = new System.Drawing.Size((pnl_cli.Width / 4) - 6, 88);
                    proc_last_month.BackColor = Color.FromArgb(153, 180, 209);
                    proc_last_month.Location  = new Point(proc_today.Width + proc_week.Width + proc_month.Width + 20, 32);
                    Label lb_proc_last_month = new Label();
                    lb_proc_last_month.AutoSize  = true;
                    lb_proc_last_month.Location  = new Point(3, 3);
                    lb_proc_last_month.Text      = "MÊS ANTERIOR";
                    lb_proc_last_month.ForeColor = Color.White;
                    lb_proc_last_month.Font      = new Font("Arial", 10, FontStyle.Bold);
                    Label lb_proc_lm_value = new Label();
                    lb_proc_lm_value.Location    = new Point(5, proc_last_month.Height / 4);
                    lb_proc_lm_value.Text        = int_proc_last_month.ToString();
                    lb_proc_lm_value.MinimumSize = new System.Drawing.Size(proc_last_month.Width - 10, (proc_last_month.Height) - (proc_last_month.Height / 3));
                    if (int_proc_last_month.ToString().Length < 4)
                    {
                        lb_proc_lm_value.Font = new Font("Arial", proc_last_month.Height / 2, FontStyle.Regular);
                    }
                    else
                    {
                        lb_proc_lm_value.Font = new Font("Arial", proc_last_month.Height / 3, FontStyle.Regular);
                    }
                    lb_proc_lm_value.TextAlign = ContentAlignment.MiddleCenter;
                    //lb_t_value.BackColor = Color.Green;
                    lb_proc_lm_value.ForeColor = Color.White;
                    proc_last_month.Controls.Add(lb_proc_last_month);
                    proc_last_month.Controls.Add(lb_proc_lm_value);

                    pnl_rec.Invoke(new Action(() => pnl_rec.Controls.Add(rec_today)));
                    pnl_rec.Invoke(new Action(() => pnl_rec.Controls.Add(rec_week)));
                    pnl_rec.Invoke(new Action(() => pnl_rec.Controls.Add(rec_month)));
                    pnl_rec.Invoke(new Action(() => pnl_rec.Controls.Add(rec_last_month)));

                    pnl_cli.Invoke(new Action(() => pnl_cli.Controls.Add(proc_today)));
                    pnl_cli.Invoke(new Action(() => pnl_cli.Controls.Add(proc_week)));
                    pnl_cli.Invoke(new Action(() => pnl_cli.Controls.Add(proc_month)));
                    pnl_cli.Invoke(new Action(() => pnl_cli.Controls.Add(proc_last_month)));

                    Thread.Sleep(2000);

                    pnl_rec.Invoke(new Action(() => pb_rec.Visible  = false));
                    pnl_cli.Invoke(new Action(() => pb_proc.Visible = false));
                }
                catch (SqlException e)
                {
                    MessageBox.Show("Aparentemente existe erro em alguma consulta com banco de dados.\n\nDetalhe do erro: " + e.Message, "Erro.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    pnl_rec.Invoke(new Action(() => pb_rec.Visible  = false));
                    pnl_cli.Invoke(new Action(() => pb_proc.Visible = false));
                }

                conn.Close();
            }

            //conn.Close();
        }
Пример #15
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);
            }
        }
Пример #16
0
        private void frm_vend_Load(object sender, EventArgs e)
        {
            SqlConnection conn = Conexao.obterConexao();

            String query = "SELECT * FROM SONIC_USUARIOS";

            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())
            {
                // SE A CONSULTA RETORNAR LINHAS
                if (DR.HasRows)
                {
                    // 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);

                        Panel pn = new Panel();
                        pn.Name      = "pn";
                        pn.Size      = new System.Drawing.Size(165, 105);
                        pn.BackColor = Color.White;
                        pn.Cursor    = Cursors.Hand;
                        PictureBox pb = new PictureBox();
                        pb.Size     = new System.Drawing.Size(82, 78);
                        pb.Image    = Properties.Resources.icon_user;
                        pb.SizeMode = PictureBoxSizeMode.StretchImage;
                        pb.Location = new Point(3, 3);
                        Label lb_cod = new Label();
                        lb_cod.Text        = values[0].ToString();
                        lb_cod.AutoSize    = true;
                        lb_cod.Font        = new Font("Letter Gothic", 16, FontStyle.Bold);
                        lb_cod.TextAlign   = ContentAlignment.MiddleCenter;
                        lb_cod.ForeColor   = Color.Gray;
                        lb_cod.MinimumSize = new System.Drawing.Size(70, 0);
                        lb_cod.Location    = new Point(90, 6);
                        Label lb_name = new Label();
                        lb_name.Text        = values[1].ToString();
                        lb_name.AutoSize    = true;
                        lb_name.Font        = new Font("Letter Gothic", 8, FontStyle.Bold);
                        lb_name.TextAlign   = ContentAlignment.MiddleCenter;
                        lb_name.ForeColor   = Color.Gray;
                        lb_name.MinimumSize = new System.Drawing.Size(155, 0);
                        lb_name.Location    = new Point(5, 86);
                        CheckBox cb = new CheckBox();
                        cb.Location = new Point(117, 50);
                        cb.Name     = "cb";

                        cb.CheckedChanged += new EventHandler(CheckBox_CheckedChanged);

                        pn.Controls.Add(pb);
                        pn.Controls.Add(lb_cod);
                        pn.Controls.Add(lb_name);
                        pn.Controls.Add(cb);

                        flp_vend.Controls.Add(pn);
                    }

                    // 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", "");
                     *  }
                     *
                     * }*/
                }
            }
        }
Пример #17
0
        private void frm_dash_Load(object sender, EventArgs e)
        {
            SqlConnection conn = Conexao.obterConexao();

            Int32 ped_today = 0;
            Int32 ped_week  = 0;
            Int32 ped_month = 0;
            Int32 cli_today = 0;
            Int32 cli_week  = 0;
            Int32 cli_month = 0;

            try {
                String     query_ped_today = "SELECT * FROM ST_PED_DAY";
                SqlCommand retorno1        = new SqlCommand(query_ped_today, conn);
                ped_today = (Int32)retorno1.ExecuteScalar();
            }
            catch (Exception)
            {
            }

            try {
                String     query_ped_week = "SELECT * FROM ST_PED_WEEK";
                SqlCommand retorno2       = new SqlCommand(query_ped_week, conn);
                ped_week = (Int32)retorno2.ExecuteScalar();
            }
            catch (Exception)
            {
            }

            try
            {
                String     query_ped_month = "SELECT * FROM ST_PED_MONTH";
                SqlCommand retorno3        = new SqlCommand(query_ped_month, conn);
                ped_month = (Int32)retorno3.ExecuteScalar();
            }
            catch (Exception)
            {
            }

            try
            {
                String     query_cli_today = "SELECT * FROM ST_CLI_DAY";
                SqlCommand retorno4        = new SqlCommand(query_cli_today, conn);
                cli_today = (Int32)retorno4.ExecuteScalar();
            }
            catch (Exception)
            {
            }

            try
            {
                String     query_cli_week = "SELECT * FROM ST_CLI_WEEK";
                SqlCommand retorno5       = new SqlCommand(query_cli_week, conn);
                cli_week = (Int32)retorno5.ExecuteScalar();
            }
            catch (Exception)
            {
            }

            try
            {
                String     query_cli_month = "SELECT * FROM ST_CLI_MONTH";
                SqlCommand retorno6        = new SqlCommand(query_cli_month, conn);
                cli_month = (Int32)retorno6.ExecuteScalar();
            }
            catch (Exception)
            {
            }

            fillDash1();
            fillDash2();
            fillDash3(ped_today.ToString(), ped_week.ToString(), ped_month.ToString(), cli_today.ToString(), cli_week.ToString(), cli_month.ToString());

            conn.Close();
        }