Last active
October 24, 2019 17:15
-
-
Save MirandinhaKL/de880c8e0e3947d8f9ba1e07292052c4 to your computer and use it in GitHub Desktop.
Postgres SQL - comandos importantes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Adiciona o ponto do milhar e permite que o usuário insira número decimal. | |
/// </summary> | |
/// <param name="sender"></param> | |
/// <param name="e"></param> | |
private void Txt_valor_KeyUp(object sender, KeyEventArgs e) | |
{ | |
try | |
{ | |
int numero_caracteres = txt_valor.Text.ToString().Count(); | |
decimal valor_monetario = Convert.ToDecimal(txt_valor.Text); | |
bool contem_virgula = txt_valor.Text.Contains(','); | |
if (numero_caracteres % 4 == 0 && !contem_virgula) | |
{ | |
txt_valor.Text = valor_monetario.ToString("N0"); | |
int cont = txt_valor.TextLength; | |
txt_valor.SelectionStart = cont; | |
txt_valor.SelectionLength = 0; | |
} | |
else if (!contem_virgula) | |
{ | |
txt_valor.Text = valor_monetario.ToString("N0"); | |
int cont = txt_valor.TextLength; | |
txt_valor.SelectionStart = cont; | |
txt_valor.SelectionLength = 0; | |
} | |
} | |
catch (Exception excecao) | |
{ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void verificaNumero(string valor) | |
{ | |
if (Int32.TryParse(valor, out valor)) | |
// se cair aqui o numero é inteiro | |
else if (Decimal.TryParse(valor, out valor)) | |
// se cair aqui o numero é decimal | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Busca na lista cliente que tenha o nome ou sobrenome de acordo com o dado informado pelo usuário. | |
string nome = txt_nome.Text.ToUpper(); | |
var lista_por_nome = lista_clientes.Where(k => k.nome.Contains(nome) || k.sobrenome.Contains(nome)).ToList(); | |
string codigo_vendedor = Form_login.dados_vendedor.cpf; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Importa os dados no formato CSV: | |
1) Colocar os arquivos em uma pasta e liberar o acesso: | |
-> Clicar com o botao direito sobre a pasta e selecionar propriedades; | |
-> Selecionar a aba segurança; | |
-> Clicar em editar | |
-> Clicar em adicionar | |
-> Digitar o nome TODOS (OK); | |
-> Clicar em todos os check boxes "Permitir"; | |
-> OK OK | |
2) Digitar no pg admin: | |
COPY nome_da_tabela FROM 'C:/Users/karine/Desktop/backup/controle_data.csv' USING DELIMITERS ';' csv header encoding 'latin-5'; | |
ou | |
COPY nome_da_tabela FROM 'C:/Users/karine/Desktop/backup/controle_data.csv' USING DELIMITERS ';'; | |
==================================================== | |
#Alterar de primary key manual para serial: | |
ALTER TABLE fator_risco drop column codigo restrict; | |
CREATE SEQUENCE public.fator_risco_id_fator_seq | |
INCREMENT 1 | |
MINVALUE 29 | |
MAXVALUE 9223372036854775807 | |
START 19 | |
CACHE 1; | |
ALTER TABLE public.fator_risco_id_fator_seq | |
OWNER TO postgres; | |
ALTER TABLE fator_risco alter id_fator SET DEFAULT NEXTVAL('fator_risco_id_fator_seq'); | |
================================================================================================= | |
#Alteração feita no banco de dados da planejar: | |
Inserindo | |
CREATE TABLE teste | |
( | |
codigo_cliente integer, | |
nome_cliente character varying(50) | |
sobrenome_cliente character varying(50) | |
endereco character varying(100), | |
cidade character varying(50), | |
telefone1 character varying(20), | |
telefone2 character varying(20), | |
email character varying(50), | |
data_nascimento date, | |
data_cadastro date | |
codigo_vendedor character varying(20) | |
) | |
insert into teste select * From cliente; | |
drop table cliente; | |
CREATE SEQUENCE public.cliente_codigo_cliente_seq | |
INCREMENT 1 | |
MINVALUE 1 | |
MAXVALUE 9223372036854775807 | |
START 1 | |
CACHE 1; | |
ALTER TABLE public.cliente_codigo_cliente_seq | |
OWNER TO postgres; | |
CREATE TABLE cliente | |
( | |
nome_cliente character varying(50) NOT NULL, | |
sobrenome_cliente character varying(50) NOT NULL, | |
endereco character varying(100), | |
cidade character varying(50), | |
telefone1 character varying(20), | |
telefone2 character varying(20), | |
email character varying(50), | |
data_nascimento date, | |
data_cadastro date NOT NULL, | |
codigo_vendedor character varying(20) NOT NULL, | |
codigo_cliente integer DEFAULT nextval('cliente_codigo_cliente_seq'::regclass) | |
) | |
alter table teste drop column codigo_cliente; | |
insert into cliente select * from teste; | |
=========================================================================================== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment