Exemple #1
0
        private void CarregaComboEstado(int CdPais)
        {
            string strSql = null;

            PrjExercicio10.clsDados Dados = null;

            try
            {
                Dados = new PrjExercicio10.clsDados();

                strSql = "SELECT * FROM ESTADO";
                if (CdPais > 0)
                {
                    strSql = strSql + " WHERE CdPais = " + CdPais;
                }
                strSql = strSql + " ORDER BY DsEstado";

                Dados.Sql = strSql;
                PrjExercicio10.clsParametros.EnderecoArquivo = "C:\\";

                CBX_Estado.DisplayMemberPath = "DsEstado";
                CBX_Estado.SelectedValuePath = "Estado";
                CBX_Estado.ItemsSource       = Dados.FU_Pesquisar().DefaultView;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                Dados  = null;
                strSql = null;
            }
        }
Exemple #2
0
        private void BTN_Excluir_Click(object sender, RoutedEventArgs e)
        {
            PrjExercicio10.clsDados Dados = null;

            try
            {
                if (TXT_CdCidade.Text.Length == 0)
                {
                    TXT_CdCidade.Focus();
                    throw new Exception("Código da cidade é obrigatório!");
                }

                Dados = new PrjExercicio10.clsDados();

                Dados.Sql = "delete from Cidade where CdCidade = " + TXT_CdCidade.Text;

                PrjExercicio10.clsParametros.EnderecoArquivo = "C:\\";
                Dados.FU_Gravar();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                Dados = null;
            }
        }
Exemple #3
0
        private void CarregaComboCidade(int INT_CdPais, string STR_Estado)
        {
            string strSQL = null;

            PrjExercicio10.clsDados Dados = null;

            try
            {
                Dados = new PrjExercicio10.clsDados();

                strSQL = " where CdPais = " + INT_CdPais;
                strSQL = strSQL + " and Estado = '" + STR_Estado + "'";

                Dados.Sql = "SELECT * FROM CIDADE " + strSQL + " ORDER BY NmCidade";

                PrjExercicio10.clsParametros.EnderecoArquivo = "C:\\";

                CBX_CdCidade.DisplayMemberPath = "NmCidade";
                CBX_CdCidade.SelectedValuePath = "CdCidade";
                CBX_CdCidade.ItemsSource       = Dados.FU_Pesquisar().DefaultView;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                strSQL = null;
                Dados  = null;
            }
        }
Exemple #4
0
        protected void BTN_Alterar_Click(object sender, EventArgs e)
        {
            string strSql;

            try
            {
                if (TXT_CdPais.Text.Length == 0)
                {
                    throw new Exception("Código do pais é obrigatório!");
                }
                if (TXT_DsPais.Text.Length == 0)
                {
                    throw new Exception("Descrição do pais é obrigatório!");
                }

                PrjExercicio10.clsDados Dados = new PrjExercicio10.clsDados();
                strSql = "update Pais set";
                strSql = strSql + " DsPais = '" + TXT_DsPais.Text + "'";
                strSql = strSql + " WHERE CdPais = " + TXT_CdPais.Text;

                Dados.Sql = strSql;
                PrjExercicio10.clsParametros.EnderecoArquivo = "C:\\";
                Dados.FU_Gravar();
            }
            catch (Exception ex)
            {
                LBL_Mensagem.Text = ex.Message;
            }
        }
Exemple #5
0
        private void BTN_Excluir_Click(object sender, RoutedEventArgs e)
        {
            PrjExercicio10.clsDados Dados = null;
            try
            {
                if (CBX_CdPais.SelectedIndex == -1)
                {
                    throw new Exception("Código do pais é obrigatório!");
                }
                if (TXT_Estado.Text.Length == 0)
                {
                    throw new Exception("Estado é obrigatório!");
                }

                Dados = new PrjExercicio10.clsDados();

                Dados.Sql = "delete from Estado where CdPais = " + CBX_CdPais.SelectedValue + " AND Estado = '" + TXT_Estado.Text + "'";

                PrjExercicio10.clsParametros.EnderecoArquivo = "C:\\";
                Dados.FU_Gravar();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                Dados = null;
            }
        }
Exemple #6
0
        protected void BTN_Incluir_Click(object sender, EventArgs e)
        {
            string strSql;

            try
            {
                if (TXT_CdPais.Text.Length == 0)
                {
                    throw new Exception("Código do pais é obrigatório!");
                }
                if (TXT_DsPais.Text.Length == 0)
                {
                    throw new Exception("Descrição do pais é obrigatório!");
                }

                PrjExercicio10.clsDados Dados = new PrjExercicio10.clsDados();
                strSql = "Insert into Pais(CdPais, DsPais) Values(";
                strSql = strSql + TXT_CdPais.Text;
                strSql = strSql + " , '" + TXT_DsPais.Text + "'";
                strSql = strSql + " )";

                Dados.Sql = strSql;
                PrjExercicio10.clsParametros.EnderecoArquivo = "C:\\";
                Dados.FU_Gravar();
            }
            catch (Exception ex)
            {
                LBL_Mensagem.Text = ex.Message;
            }
        }
Exemple #7
0
        private void SU_Montar_Tela(Decimal DEC_CdCliente)
        {
            string    strSql;
            DataTable LDTT_Cliente = null;

            PrjExercicio10.clsDados Dados = null;

            try
            {
                if (DEC_CdCliente != 0)
                {
                    Dados     = new PrjExercicio10.clsDados();
                    strSql    = " where CdCliente = " + DEC_CdCliente.ToString();
                    Dados.Sql = "select CLIENTE.*, CIDADE.CdPais, CIDADE.Estado from CLIENTE INNER JOIN CIDADE ON (CIDADE.CdCidade = CLIENTE.CdCidade) " + strSql;

                    PrjExercicio10.clsParametros.EnderecoArquivo = "C:\\";
                    LDTT_Cliente = Dados.FU_Pesquisar();
                    if (LDTT_Cliente.Rows.Count > 0)
                    {
                        BTN_Incluir.IsEnabled = false;
                        BTN_Alterar.IsEnabled = true;
                        BTN_Excluir.IsEnabled = true;

                        TXT_CdCliente.Text  = LDTT_Cliente.Rows[0]["CdCliente"].ToString();
                        TXT_NmCliente.Text  = LDTT_Cliente.Rows[0]["NmCliente"].ToString();
                        TXT_Endereco.Text   = LDTT_Cliente.Rows[0]["Endereco"].ToString();
                        TXT_Bairro.Text     = LDTT_Cliente.Rows[0]["Bairro"].ToString();
                        TXT_CEP.Text        = LDTT_Cliente.Rows[0]["CEP"].ToString();
                        TXT_EndEmail.Text   = LDTT_Cliente.Rows[0]["EndEmail"].ToString();
                        TXT_DocIdentif.Text = LDTT_Cliente.Rows[0]["DocIdentif"].ToString();
                        TXT_GcgCpf.Text     = LDTT_Cliente.Rows[0]["CgcCpf"].ToString();

                        CBX_CdPais.SelectedValue = LDTT_Cliente.Rows[0]["CdPais"].ToString();

                        CarregaComboEstado(Convert.ToInt32(LDTT_Cliente.Rows[0]["CdPais"].ToString()));
                        CBX_Estado.SelectedValue = LDTT_Cliente.Rows[0]["Estado"].ToString();

                        CarregaComboCidade(Convert.ToInt32(LDTT_Cliente.Rows[0]["CdPais"].ToString()), LDTT_Cliente.Rows[0]["Estado"].ToString());
                        CBX_CdCidade.SelectedValue = LDTT_Cliente.Rows[0]["CdCidade"].ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                LDTT_Cliente = null;
                Dados        = null;
            }
        }
Exemple #8
0
        private void BTN_Incluir_Click(object sender, RoutedEventArgs e)
        {
            string strSql;

            PrjExercicio10.clsDados Dados = null;

            try
            {
                if (CBX_CdPais.SelectedIndex == -1)
                {
                    CBX_CdPais.Focus();
                    MessageBox.Show("Código do pais é obrigatório!");
                    return;
                }
                if (CBX_Estado.SelectedIndex == -1)
                {
                    CBX_Estado.Focus();
                    throw new Exception("Estado é obrigatório!");
                }
                if (TXT_CdCidade.Text.Length == 0)
                {
                    TXT_CdCidade.Focus();
                    throw new Exception("Código da cidade é obrigatório!");
                }
                if (TXT_NmCidade.Text.Length == 0)
                {
                    TXT_NmCidade.Focus();
                    throw new Exception("Nome da cidade é obrigatório!");
                }

                Dados  = new PrjExercicio10.clsDados();
                strSql = "Insert into Cidade(CdCidade, NmCidade, CdPais, Estado) Values(";
                strSql = strSql + TXT_CdCidade.Text;
                strSql = strSql + " , '" + TXT_NmCidade.Text + "'";
                strSql = strSql + " , " + CBX_CdPais.SelectedValue;
                strSql = strSql + " , '" + CBX_Estado.SelectedValue + "'";
                strSql = strSql + " )";

                Dados.Sql = strSql;
                PrjExercicio10.clsParametros.EnderecoArquivo = "C:\\";
                Dados.FU_Gravar();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                Dados = null;
            }
        }
Exemple #9
0
        private void BTN_Alterar_Click(object sender, RoutedEventArgs e)
        {
            string strSql;

            PrjExercicio10.clsDados Dados = null;

            try
            {
                if (CBX_CdPais.SelectedIndex == -1)
                {
                    CBX_CdPais.Focus();
                    throw new Exception("Código do pais é obrigatório!");
                }
                if (CBX_Estado.SelectedIndex == -1)
                {
                    CBX_Estado.Focus();
                    throw new Exception("Estado é obrigatório!");
                }
                if (TXT_CdCidade.Text.Length == 0)
                {
                    TXT_CdCidade.Focus();
                    throw new Exception("Código da cidade é obrigatório!");
                }
                if (TXT_NmCidade.Text.Length == 0)
                {
                    TXT_NmCidade.Focus();
                    throw new Exception("Nome da cidade é obrigatório!");
                }

                Dados  = new PrjExercicio10.clsDados();
                strSql = "update Cidade set";
                strSql = strSql + " NmCidade = '" + TXT_NmCidade.Text + "'";
                strSql = strSql + " , CdPais = '" + CBX_CdPais.SelectedValue + "'";
                strSql = strSql + " , Estado = '" + CBX_Estado.SelectedValue + "'";
                strSql = strSql + " WHERE CdCidade = " + TXT_CdCidade.Text;

                Dados.Sql = strSql;
                PrjExercicio10.clsParametros.EnderecoArquivo = "C:\\";
                Dados.FU_Gravar();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                Dados = null;
            }
        }
Exemple #10
0
        private void SU_Montar_Tela(Int32 INT_CdCidade)
        {
            string    strSql;
            DataTable LDTT_Cidade;

            PrjExercicio10.clsDados Dados = null;

            try
            {
                if (INT_CdCidade != 0)
                {
                    Dados     = new PrjExercicio10.clsDados();
                    strSql    = " where CdCidade = " + INT_CdCidade.ToString();
                    Dados.Sql = "select * from CIDADE " + strSql;
                    PrjExercicio10.clsParametros.EnderecoArquivo = "C:\\";
                    LDTT_Cidade = Dados.FU_Pesquisar();
                    if (LDTT_Cidade.Rows.Count > 0)
                    {
                        BTN_Incluir.IsEnabled = false;
                        BTN_Alterar.IsEnabled = true;
                        BTN_Excluir.IsEnabled = true;

                        CBX_CdPais.SelectedValue = LDTT_Cidade.Rows[0]["CdPais"].ToString();

                        // remonta o combo de estados porque pode ter mudado o pais e estar com os estados do outro pais
                        CarregaComboEstado(Convert.ToInt32(LDTT_Cidade.Rows[0]["CdPais"].ToString()));

                        CBX_Estado.SelectedValue = LDTT_Cidade.Rows[0]["Estado"].ToString();
                        TXT_CdCidade.Text        = LDTT_Cidade.Rows[0]["CdCidade"].ToString();
                        TXT_NmCidade.Text        = LDTT_Cidade.Rows[0]["NmCidade"].ToString();
                    }
                    else
                    {
                        TXT_NmCidade.Text = "";
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                LDTT_Cidade = null;
                Dados       = null;
                strSql      = null;
            }
        }
Exemple #11
0
        public void wmIncluir(clsPais cPais)
        {
            string strSql;

            PrjExercicio10.clsDados Dados = null;

            try
            {
                if (cPais == null)
                {
                    throw new Exception("Classe pais não foi iniciada!");
                }
                if (cPais.CdPais == 0)
                {
                    throw new Exception("Código do pais não foi Informado!");
                }
                if (cPais.DsPais == null)
                {
                    throw new Exception("Descrição do pais não foi iniciada!");
                }

                if (cPais.DsPais.ToString().Length == 0)
                {
                    throw new Exception("Descrição do pais é obrigatório!");
                }

                Dados  = new PrjExercicio10.clsDados();
                strSql = "Insert into Pais(CdPais, DsPais) Values(";
                strSql = strSql + cPais.CdPais;
                strSql = strSql + " , '" + cPais.DsPais + "'";
                strSql = strSql + " )";

                Dados.Sql = strSql;
                PrjExercicio10.clsParametros.EnderecoArquivo = "C:\\";
                Dados.FU_Gravar();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                Dados = null;
            }
        }
Exemple #12
0
        private void SU_Montar_Tela(Int32 INT_CdPais)
        {
            string    strSql;
            DataTable LDTT_Pais;

            PrjExercicio10.clsDados Dados = null;

            try
            {
                if (INT_CdPais != 0)
                {
                    Dados     = new PrjExercicio10.clsDados();
                    strSql    = " where CdPais = " + INT_CdPais.ToString();
                    Dados.Sql = "select * from pais" + strSql;
                    PrjExercicio10.clsParametros.EnderecoArquivo = "C:\\";
                    LDTT_Pais = Dados.FU_Pesquisar();
                    if (LDTT_Pais.Rows.Count > 0)
                    {
                        BTN_Incluir.IsEnabled = false;
                        BTN_Alterar.IsEnabled = true;
                        BTN_Excluir.IsEnabled = true;

                        TXT_CdPais.Text = LDTT_Pais.Rows[0]["CdPais"].ToString();
                        TXT_DsPais.Text = LDTT_Pais.Rows[0]["DsPais"].ToString();
                    }
                    else
                    {
                        TXT_DsPais.Text = "";
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                LDTT_Pais = null;
                strSql    = null;
                Dados     = null;
            }
        }
Exemple #13
0
        protected void BTN_Excluir_Click(object sender, EventArgs e)
        {
            try
            {
                if (TXT_CdPais.Text.Length == 0)
                {
                    throw new Exception("Código do pais é obrigatório!");
                }

                PrjExercicio10.clsDados Dados = new PrjExercicio10.clsDados();

                Dados.Sql = "delete from Pais where CdPais = " + TXT_CdPais.Text;
                PrjExercicio10.clsParametros.EnderecoArquivo = "C:\\";
                Dados.FU_Gravar();
            }
            catch (Exception ex)
            {
                LBL_Mensagem.Text = ex.Message;
            }
        }
Exemple #14
0
        private void BTN_Incluir_Click(object sender, RoutedEventArgs e)
        {
            string strSql;

            PrjExercicio10.clsDados Dados = null;

            try
            {
                if (CBX_CdPais.SelectedIndex == -1)
                {
                    throw new Exception("Código do pais é obrigatório!");
                }
                if (TXT_Estado.Text.Trim().Length == 0)
                {
                    throw new Exception("Sigla do Estado é obrigatório!");
                }
                if (TXT_DsEstado.Text.Trim().Length == 0)
                {
                    throw new Exception("Descrição do estado é obrigatório!");
                }

                Dados  = new PrjExercicio10.clsDados();
                strSql = "Insert into Estado(CdPais, Estado, DsEstado) Values(";
                strSql = strSql + CBX_CdPais.SelectedValue;
                strSql = strSql + " , '" + TXT_Estado.Text + "'";
                strSql = strSql + " , '" + TXT_DsEstado.Text + "'";
                strSql = strSql + " )";

                Dados.Sql = strSql;
                PrjExercicio10.clsParametros.EnderecoArquivo = "C:\\";
                Dados.FU_Gravar();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                Dados = null;
            }
        }
Exemple #15
0
        private void SU_Montar_Tela(Int32 INT_CdPais, string STR_Estado)
        {
            string    strSql;
            DataTable LDTT_Estado;

            try
            {
                if (INT_CdPais != 0 && STR_Estado.Trim() != "")
                {
                    PrjExercicio10.clsDados Dados = new PrjExercicio10.clsDados();
                    strSql    = " where CdPais = " + INT_CdPais.ToString();
                    strSql   += " and Estado = '" + STR_Estado.ToString() + "'";
                    Dados.Sql = "select * from ESTADO " + strSql;
                    PrjExercicio10.clsParametros.EnderecoArquivo = "C:\\";
                    LDTT_Estado = Dados.FU_Pesquisar();
                    if (LDTT_Estado.Rows.Count > 0)
                    {
                        BTN_Incluir.IsEnabled = false;
                        BTN_Alterar.IsEnabled = true;
                        BTN_Excluir.IsEnabled = true;

                        CBX_CdPais.SelectedValue = LDTT_Estado.Rows[0]["CdPais"].ToString();
                        TXT_Estado.Text          = LDTT_Estado.Rows[0]["Estado"].ToString();
                        TXT_DsEstado.Text        = LDTT_Estado.Rows[0]["DsEstado"].ToString();
                    }
                    else
                    {
                        TXT_DsEstado.Text = "";
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                LDTT_Estado = null;
            }
        }
Exemple #16
0
        private void BTN_Alterar_Click(object sender, RoutedEventArgs e)
        {
            string strSql;

            PrjExercicio10.clsDados Dados = null;

            try
            {
                if (CBX_CdPais.SelectedIndex == -1)
                {
                    throw new Exception("Código do pais é obrigatório!");
                }
                if (TXT_Estado.Text.Length == 0)
                {
                    throw new Exception("Estado é obrigatório!");
                }
                if (TXT_DsEstado.Text.Length == 0)
                {
                    throw new Exception("Descrição do estado é obrigatório!");
                }

                Dados  = new PrjExercicio10.clsDados();
                strSql = "update Estado set";
                strSql = strSql + " DsEstado = '" + TXT_DsEstado.Text + "'";
                strSql = strSql + " WHERE CdPais = " + CBX_CdPais.SelectedValue;
                strSql = strSql + " AND Estado = '" + TXT_Estado.Text + "'";

                Dados.Sql = strSql;
                PrjExercicio10.clsParametros.EnderecoArquivo = "C:\\";
                Dados.FU_Gravar();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                Dados = null;
            }
        }
Exemple #17
0
        private void CarregaComboPais()
        {
            PrjExercicio10.clsDados Dados = null;
            try
            {
                Dados     = new PrjExercicio10.clsDados();
                Dados.Sql = "SELECT * FROM PAIS ORDER BY DsPais";
                PrjExercicio10.clsParametros.EnderecoArquivo = "C:\\";

                CBX_CdPais.DisplayMemberPath = "DsPais";
                CBX_CdPais.SelectedValuePath = "CdPais";
                CBX_CdPais.ItemsSource       = Dados.FU_Pesquisar().DefaultView;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                Dados = null;
            }
        }
Exemple #18
0
        public DataSet wmSelecionar(clsPais cPais)
        {
            DataSet dtsRetorno = null;
            string  strSql;

            try
            {
                PrjExercicio10.clsDados Dados = new PrjExercicio10.clsDados();
                strSql = "";

                if (cPais.CdPais > 0)
                {
                    strSql = " where CdPais = " + cPais.CdPais;
                }

                if (strSql.Length == 0)
                {
                    if (cPais.DsPais != null)
                    {
                        if (cPais.DsPais.Length > 0)
                        {
                            strSql = " where DsPais like '" + cPais.DsPais + "%'";
                        }
                    }
                }

                Dados.Sql = "select * from pais" + strSql;

                PrjExercicio10.clsParametros.EnderecoArquivo = "C:\\";
                dtsRetorno = new DataSet();
                dtsRetorno.Tables.Add(Dados.FU_Pesquisar());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return(dtsRetorno);
        }
Exemple #19
0
        public void wmAtualizar(clsPais cPais)
        {
            string strSql;

            try
            {
                if (cPais == null)
                {
                    throw new Exception("Classe pais não foi iniciada!");
                }
                if (cPais.CdPais == 0)
                {
                    throw new Exception("Código do pais não foi iniciado!");
                }
                if (cPais.DsPais == null)
                {
                    throw new Exception("Descrição do pais não foi iniciada!");
                }

                if (cPais.DsPais.ToString().Length == 0)
                {
                    throw new Exception("Descrição do pais é obrigatório!");
                }

                PrjExercicio10.clsDados Dados = new PrjExercicio10.clsDados();
                strSql = "update Pais set";
                strSql = strSql + " DsPais = '" + cPais.DsPais + "'";
                strSql = strSql + " WHERE CdPais = " + cPais.CdPais;

                Dados.Sql = strSql;
                PrjExercicio10.clsParametros.EnderecoArquivo = "C:\\";
                Dados.FU_Gravar();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemple #20
0
        protected void Btn_Selecionar_Click(object sender, EventArgs e)
        {
            string strSql;

            try
            {
                PrjExercicio10.clsDados Dados = new PrjExercicio10.clsDados();
                strSql = "";

                if (TXT_CdPais.Text.Length > 0)
                {
                    strSql = " where CdPais = " + TXT_CdPais.Text;
                }
                if (TXT_DsPais.Text.Length > 0)
                {
                    if (strSql.Length == 0)
                    {
                        strSql = " where DsPais = '" + TXT_DsPais.Text + "'";
                    }
                    else
                    {
                        strSql = strSql + " and DsPais = '" + TXT_DsPais.Text + "'";
                    }
                }

                Dados.Sql = "select * from pais" + strSql;

                PrjExercicio10.clsParametros.EnderecoArquivo = "C:\\";

                GridView1.DataSource = Dados.FU_Pesquisar();
                GridView1.DataBind();
            }
            catch (Exception ex)
            {
                LBL_Mensagem.Text = ex.Message;
            }
        }
Exemple #21
0
        public void wmExcluir(clsPais cPais)
        {
            try
            {
                if (cPais == null)
                {
                    throw new Exception("Classe pais não foi iniciada!");
                }
                if (cPais.CdPais == 0)
                {
                    throw new Exception("Código do pais não foi iniciado!");
                }

                PrjExercicio10.clsDados Dados = new PrjExercicio10.clsDados();

                Dados.Sql = "delete from Pais where CdPais = " + cPais.CdPais;
                PrjExercicio10.clsParametros.EnderecoArquivo = "C:\\";
                Dados.FU_Gravar();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemple #22
0
        private void BTN_Selecionar_Click(object sender, RoutedEventArgs e)
        {
            string strSql;

            PrjExercicio10.clsDados Dados = null;
            DataGridTextColumn      Aux   = null;

            try
            {
                strSql = "";
                Dados  = new PrjExercicio10.clsDados();

                if (CBX_CdPais.SelectedIndex != -1)
                {
                    strSql = " where estado.CdPais = " + CBX_CdPais.SelectedValue;
                }
                if (TXT_Estado.Text.Length > 0)
                {
                    if (strSql.Length == 0)
                    {
                        strSql = " where estado.Estado = '" + TXT_Estado.Text + "'";
                    }
                    else
                    {
                        strSql = strSql + " and estado.Estado = '" + TXT_Estado.Text + "'";
                    }
                }
                if (TXT_DsEstado.Text.Length > 0)
                {
                    if (strSql.Length == 0)
                    {
                        strSql = " where estado.DsEstado like '" + TXT_DsEstado.Text + "%'";
                    }
                    else
                    {
                        strSql = strSql + " and estado.DsEstado like '" + TXT_DsEstado.Text + "%'";
                    }
                }

                Dados.Sql = "select estado.*, Pais.DsPais from estado INNER JOIN Pais ON Pais.CdPais = estado.CdPais " + strSql;

                PrjExercicio10.clsParametros.EnderecoArquivo = "C:\\";

                DTG_Estado.Columns.Clear();
                DTG_Estado.AutoGenerateColumns = false;
                DTG_Estado.IsReadOnly          = true;

                BTN_Alterar.IsEnabled = false;
                BTN_Excluir.IsEnabled = false;
                BTN_Incluir.IsEnabled = true;

                Aux                = new DataGridTextColumn();
                Aux.Binding        = new Binding("CdPais");
                Aux.Width          = 80;
                Aux.Header         = "Código";
                Aux.SortMemberPath = "CdPais";
                Aux.Visibility     = System.Windows.Visibility.Hidden;
                DTG_Estado.Columns.Add(Aux);

                Aux                = new DataGridTextColumn();
                Aux.Binding        = new Binding("DsPais");
                Aux.Width          = 100;
                Aux.Header         = "Pais";
                Aux.SortMemberPath = "DsPais";
                Aux.Visibility     = System.Windows.Visibility.Visible;
                DTG_Estado.Columns.Add(Aux);

                Aux                = new DataGridTextColumn();
                Aux.Binding        = new Binding("Estado");
                Aux.Width          = 100;
                Aux.Header         = "Estado";
                Aux.SortMemberPath = "Estado";
                Aux.Visibility     = System.Windows.Visibility.Visible;
                DTG_Estado.Columns.Add(Aux);

                Aux                = new DataGridTextColumn();
                Aux.Binding        = new Binding("DsEstado");
                Aux.Width          = 200;
                Aux.Header         = "Descricão";
                Aux.SortMemberPath = "DsEstado";
                Aux.Visibility     = System.Windows.Visibility.Visible;
                DTG_Estado.Columns.Add(Aux);

                DTG_Estado.ItemsSource = Dados.FU_Pesquisar().DefaultView;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                Dados  = null;
                strSql = null;
                Aux    = null;
            }
        }
Exemple #23
0
        private void BTN_Selecionar_Click(object sender, RoutedEventArgs e)
        {
            string strSql;

            PrjExercicio10.clsDados Dados = null;

            try
            {
                Dados  = new PrjExercicio10.clsDados();
                strSql = "";

                if (CBX_CdCidade.SelectedIndex != -1)
                {
                    strSql = " where Cliente.CdCidade = " + CBX_CdCidade.SelectedValue;
                }

                if (CBX_CdPais.SelectedIndex != -1)
                {
                    if (strSql.Length == 0)
                    {
                        strSql = " where Cidade.CdPais = " + CBX_CdPais.SelectedValue;
                    }
                    else
                    {
                        strSql = " and Cidade.CdPais = " + CBX_CdPais.SelectedValue;
                    }
                }

                if (CBX_Estado.SelectedIndex != -1)
                {
                    if (strSql.Length == 0)
                    {
                        strSql = " where Cidade.Estado = '" + CBX_Estado.SelectedValue + "'";
                    }
                    else
                    {
                        strSql = " and Cidade.Estado = '" + CBX_Estado.SelectedValue + "'";
                    }
                }

                if (TXT_NmCliente.Text.Length > 0)
                {
                    if (strSql.Length == 0)
                    {
                        strSql = " where Cliente.NmCliente like '" + TXT_NmCliente.Text + "%'";
                    }
                    else
                    {
                        strSql = strSql + " and Cliente.NmCliente like '" + TXT_NmCliente.Text + "%'";
                    }
                }
                if (TXT_GcgCpf.Text.Length > 0)
                {
                    if (strSql.Length == 0)
                    {
                        strSql = " where Cliente.CgcCpf = '" + TXT_GcgCpf.Text + "'";
                    }
                    else
                    {
                        strSql = strSql + " and Cliente.CgcCpf = '" + TXT_GcgCpf.Text + "'";
                    }
                }
                if (TXT_Endereco.Text.Length > 0)
                {
                    if (strSql.Length == 0)
                    {
                        strSql = " where Cliente.Endereco = '" + TXT_Endereco.Text + "'";
                    }
                    else
                    {
                        strSql = strSql + " and Cliente.Endereco = '" + TXT_Endereco.Text + "'";
                    }
                }
                if (TXT_Bairro.Text.Length > 0)
                {
                    if (strSql.Length == 0)
                    {
                        strSql = " where Cliente.Bairro = '" + TXT_Bairro.Text + "'";
                    }
                    else
                    {
                        strSql = strSql + " and Cliente.Bairro = '" + TXT_Bairro.Text + "'";
                    }
                }
                if (TXT_CEP.Text.Length > 0)
                {
                    if (strSql.Length == 0)
                    {
                        strSql = " where Cliente.CEP = '" + TXT_CEP.Text + "'";
                    }
                    else
                    {
                        strSql = strSql + " and Cliente.CEP = '" + TXT_CEP.Text + "'";
                    }
                }
                if (TXT_EndEmail.Text.Length > 0)
                {
                    if (strSql.Length == 0)
                    {
                        strSql = " where Cliente.EndEmail = '" + TXT_EndEmail.Text + "'";
                    }
                    else
                    {
                        strSql = strSql + " and Cliente.EndEmail = '" + TXT_EndEmail.Text + "'";
                    }
                }
                if (TXT_DocIdentif.Text.Length > 0)
                {
                    if (strSql.Length == 0)
                    {
                        strSql = " where Cliente.DocIdentif = '" + TXT_DocIdentif.Text + "'";
                    }
                    else
                    {
                        strSql = strSql + " and Cliente.DocIdentif = '" + TXT_DocIdentif.Text + "'";
                    }
                }

                Dados.Sql = "select Cliente.*, CIDADE.CdPais, CIDADE.Estado from Cliente INNER JOIN Cidade ON (Cidade.CdCidade = Cliente.CdCidade) " + strSql;

                PrjExercicio10.clsParametros.EnderecoArquivo = "C:\\";

                DTG_Cliente.Columns.Clear();
                DTG_Cliente.AutoGenerateColumns = false;
                DTG_Cliente.IsReadOnly          = true;

                BTN_Incluir.IsEnabled = true;
                BTN_Alterar.IsEnabled = false;
                BTN_Excluir.IsEnabled = false;

                DataGridTextColumn Aux = null;

                Aux                = new DataGridTextColumn();
                Aux.Binding        = new Binding("CdCidade");
                Aux.Width          = 80;
                Aux.Header         = "Código";
                Aux.SortMemberPath = "CdCidade";
                Aux.Visibility     = System.Windows.Visibility.Hidden;
                DTG_Cliente.Columns.Add(Aux);

                Aux                = new DataGridTextColumn();
                Aux.Binding        = new Binding("CdCliente");
                Aux.Width          = 80;
                Aux.Header         = "Código";
                Aux.SortMemberPath = "CdCliente";
                Aux.Visibility     = System.Windows.Visibility.Visible;
                DTG_Cliente.Columns.Add(Aux);

                Aux                = new DataGridTextColumn();
                Aux.Binding        = new Binding("NmCliente");
                Aux.Width          = 200;
                Aux.Header         = "Nome";
                Aux.SortMemberPath = "NmCliente";
                Aux.Visibility     = System.Windows.Visibility.Visible;
                DTG_Cliente.Columns.Add(Aux);

                Aux                = new DataGridTextColumn();
                Aux.Binding        = new Binding("CgcCpf");
                Aux.Width          = 100;
                Aux.Header         = "Cgc/Cpf";
                Aux.SortMemberPath = "CgcCpf";
                Aux.Visibility     = System.Windows.Visibility.Visible;
                DTG_Cliente.Columns.Add(Aux);

                Aux                = new DataGridTextColumn();
                Aux.Binding        = new Binding("DocIdentif");
                Aux.Width          = 100;
                Aux.Header         = "Identidade";
                Aux.SortMemberPath = "DocIdentif";
                Aux.Visibility     = System.Windows.Visibility.Visible;
                DTG_Cliente.Columns.Add(Aux);

                Aux                = new DataGridTextColumn();
                Aux.Binding        = new Binding("Endereco");
                Aux.Width          = 200;
                Aux.Header         = "Endereço";
                Aux.SortMemberPath = "Endereco";
                Aux.Visibility     = System.Windows.Visibility.Visible;
                DTG_Cliente.Columns.Add(Aux);

                Aux                = new DataGridTextColumn();
                Aux.Binding        = new Binding("Bairro");
                Aux.Width          = 100;
                Aux.Header         = "Bairro";
                Aux.SortMemberPath = "Bairro";
                Aux.Visibility     = System.Windows.Visibility.Visible;
                DTG_Cliente.Columns.Add(Aux);

                Aux                = new DataGridTextColumn();
                Aux.Binding        = new Binding("Cep");
                Aux.Width          = 80;
                Aux.Header         = "Cep";
                Aux.SortMemberPath = "Cep";
                Aux.Visibility     = System.Windows.Visibility.Visible;
                DTG_Cliente.Columns.Add(Aux);

                Aux                = new DataGridTextColumn();
                Aux.Binding        = new Binding("NmCidade");
                Aux.Width          = 100;
                Aux.Header         = "Cidade";
                Aux.SortMemberPath = "NmCidade";
                Aux.Visibility     = System.Windows.Visibility.Visible;
                DTG_Cliente.Columns.Add(Aux);

                Aux                = new DataGridTextColumn();
                Aux.Binding        = new Binding("EndEmail");
                Aux.Width          = 100;
                Aux.Header         = "Email";
                Aux.SortMemberPath = "EndEmail";
                Aux.Visibility     = System.Windows.Visibility.Visible;
                DTG_Cliente.Columns.Add(Aux);

                DTG_Cliente.ItemsSource = Dados.FU_Pesquisar().DefaultView;

                SU_Limpar_Tela();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                Dados = null;
            }
        }
Exemple #24
0
        private void BTN_Alterar_Click(object sender, RoutedEventArgs e)
        {
            string strSql;

            PrjExercicio10.clsDados Dados = null;

            try
            {
                if (TXT_CdCliente.Text.Length == 0)
                {
                    throw new Exception("Código do cliente é obrigatório!");
                }
                if (TXT_NmCliente.Text.Length == 0)
                {
                    throw new Exception("Nome do cliente é obrigatório!");
                }
                if (TXT_GcgCpf.Text.Length == 0)
                {
                    throw new Exception("Cgc/Cpf do cliente é obrigatório!");
                }
                if (TXT_Endereco.Text.Length == 0)
                {
                    throw new Exception("Endereço do cliente é obrigatório!");
                }
                if (TXT_Bairro.Text.Length == 0)
                {
                    throw new Exception("Bairro do cliente é obrigatório!");
                }
                if (TXT_CEP.Text.Length == 0)
                {
                    throw new Exception("Cep do cliente é obrigatório!");
                }
                if (CBX_CdCidade.SelectedIndex == -1)
                {
                    throw new Exception("Código da cidade é obrigatório!");
                }
                if (TXT_DocIdentif.Text.Length == 0)
                {
                    throw new Exception("Identidade do cliente é obrigatório!");
                }

                if (TXT_EndEmail.Text.Trim() != "")
                {
                    if (ClsValidacao.Fu_Consistir_Email(TXT_EndEmail.Text) == false)
                    {
                        throw new Exception("Endereço de Email informado é inválido!");
                    }
                }

                Dados  = new PrjExercicio10.clsDados();
                strSql = "update Cliente set";
                strSql = strSql + " NmCliente = '" + TXT_NmCliente.Text + "'";
                strSql = strSql + " , CgcCpf = " + TXT_GcgCpf.Text;
                strSql = strSql + " , Endereco = '" + TXT_Endereco.Text + "'";
                strSql = strSql + " , Bairro = '" + TXT_Bairro.Text + "'";
                strSql = strSql + " , Cep = " + TXT_CEP.Text;
                strSql = strSql + " , CdCidade = " + CBX_CdCidade.SelectedValue;
                strSql = strSql + " , EndEmail = '" + TXT_EndEmail.Text + "'";
                strSql = strSql + " , DocIdentif = '" + TXT_DocIdentif.Text + "'";
                strSql = strSql + " WHERE CdCliente = " + TXT_CdCliente.Text;

                Dados.Sql = strSql;
                PrjExercicio10.clsParametros.EnderecoArquivo = "C:\\";
                Dados.FU_Gravar();

                SU_Limpar_Tela();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                Dados = null;
            }
        }