예제 #1
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;
            }
        }
예제 #2
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;
            }
        }