public void CadastroNovoEmprestimo(tb_emprestimo dto, string ra, string email) { try { DateTime ontem = DateTime.Today; ontem = ontem.AddDays(-1); if (dto.dt_devolucao.Day - DateTime.Today.Day < 0) { throw new ArgumentException("Impossivel devolver um livro ontem!"); } ValidarTexto val = new ValidarTexto(); val.ValidarEmail(email); val.ValidarNome(dto.nm_funcionario); AzureBiblioteca db = new AzureBiblioteca(); tb_turma_aluno data = db.tb_turma_aluno.Where(x => x.cd_ra == ra).ToList().Single(); CriarNotificacao(data, email); dto.tb_turma_aluno_id_turma_aluno = data.id_aluno; dto.tb_notificacao_id_notificacao = idNot; EmprestimoDB.CadastroNovoEmprestimo(dto); } catch (ArgumentException ex) { System.Windows.Forms.MessageBox.Show($"{ex.Message}", "Biblioteca", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show($"Ocorreu um erro inexperado: {ex.Message}", "Biblioteca", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public int AlterarFuncionario(FuncionarioDTO dto) { ValidarNumero regexNum = new ValidarNumero(); ValidarTexto regexTxt = new ValidarTexto(); regexTxt.ValidarEmail(dto.ds_Email); regexTxt.ValidarNome(dto.nm_NomeFunc); regexNum.ValidarTelefoneFixo(dto.num_Telefone); regexNum.ValidarTelefoneCelular(dto.num_Celular); Email email = new Email(); email.Validar(dto.ds_Email, dto.nm_NomeFunc); CPF validar = new CPF(); validar.ValidarCPF(dto.ds_CPF); decimal idade = DateTime.Now.Year - dto.dt_Nasc.Year; if (idade < 18) { throw new ArgumentException("Não é possível cadastrar funcionários menores de 18 anos."); } if (dto.ds_Logradouro == string.Empty) { throw new ArgumentException("Logradouro não pode ser nulo."); } if (dto.ds_Bairro == string.Empty) { throw new ArgumentException("Bairro não pode ser nulo."); } if (dto.ds_UF == string.Empty) { throw new ArgumentException("UF não pode ser nula."); } if (dto.num_Residencia == string.Empty) { throw new ArgumentException("Número de residencia não pode ser nulo."); } DESCripto cripto = new DESCripto(); dto.nm_NomeFunc = cripto.Criptografar(Program.chave, dto.nm_NomeFunc); dto.ds_CPF = cripto.Criptografar(Program.chave, dto.ds_CPF); dto.num_Celular = cripto.Criptografar(Program.chave, dto.num_Celular); dto.num_Telefone = cripto.Criptografar(Program.chave, dto.num_Telefone); dto.ds_Email = cripto.Criptografar(Program.chave, dto.ds_Email); FuncionarioDatabase db = new FuncionarioDatabase(); return(db.AlterarFuncionario(dto)); }
/* * public bool Save2() * { * String sql = @" * SELECT * (SELECT COUNT(*) FROM SEDES_SAT_CATALOGOS WHERE ID_CATALOGO='MP' AND CVE_SEDE=CAT.CVE_SEDE) AS 'MP' * ,(SELECT COUNT(*) FROM SEDES_SAT_CATALOGOS WHERE ID_CATALOGO='FP' AND CVE_SEDE=CAT.CVE_SEDE) AS 'FP' * ,(SELECT COUNT(*) FROM SEDES_SAT_CATALOGOS WHERE ID_CATALOGO='CPS' AND CVE_SEDE=CAT.CVE_SEDE) AS 'CPS' * ,(SELECT COUNT(*) FROM SEDES_SAT_CATALOGOS WHERE ID_CATALOGO='CU' AND CVE_SEDE=CAT.CVE_SEDE) AS 'CU' * ,(SELECT COUNT(*) FROM SEDES_SAT_CATALOGOS WHERE ID_CATALOGO='VPDF' AND CVE_SEDE=CAT.CVE_SEDE) AS 'VPDF' * FROM (SELECT '" + this.ClaveSede + @"'AS'CVE_SEDE') AS CAT * "; * Catalogo[] catalogos = new Catalogo[] * { * new Catalogo(){ Id="MP", Clave=this.MetodoPago, Existe=false }, * new Catalogo(){ Id="FP", Clave=this.FormaPago, Existe=false }, * new Catalogo(){ Id="CPS", Clave=this.ClaveProductoServicio, Existe=false }, * new Catalogo(){ Id="CU", Clave=this.ClaveUnidad, Existe=false }, * new Catalogo(){ Id="VPDF", Clave=this.ValidarPDF, Existe=false }, * }; * ResultSet res = db.getTable(sql); * if (res.Next()) * { * StringWriter sw = new StringWriter(); * foreach (Catalogo catalogo in catalogos) * { * sw.GetStringBuilder().Clear(); * if (catalogo.Clave != "_DEFAULT_") * { * catalogo.Existe = res.GetInt(catalogo.Id) > 0; * * if (catalogo.Existe) * sw.Write("UPDATE SEDES_SAT_CATALOGOS SET CLAVE='{0}' WHERE CVE_SEDE='{1}' AND ID_CATALOGO='{2}'", catalogo.Clave, this.ClaveSede, catalogo.Id); * else * sw.Write("INSERT INTO SEDES_SAT_CATALOGOS (CVE_SEDE,ID_CATALOGO,CLAVE,USUARIO) VALUES ('{0}','{1}','{2}','{3}')", this.ClaveSede, catalogo.Id, catalogo.Clave, sesion.nickName); * db.execute(sw.ToString()); * } * else * { * sw.Write("DELETE SEDES_SAT_CATALOGOS WHERE CVE_SEDE='{0}' AND ID_CATALOGO='{1}'", this.ClaveSede, catalogo.Id); * db.execute(sw.ToString()); * } * } * return true; * } * return false; * } * //*/ public static Dictionary <string, ValidarTexto> ConsultaValidaciones(string cve_sede, SuperModel model) { string sql = @"SELECT CS.PK_CATALOGO, C.CVE_CATALOGO, C.CATALOGO, ISNULL(CS.PK_OPCION,0) AS 'PK_OPCION', CO.OPCION, C.METODO_BUSQUEDA FROM SAT_CATALOGOS_SEDES CS INNER JOIN SAT_CATALOGOS C ON C.PK1 = CS.PK_CATALOGO AND C.ACTIVO = 1 LEFT JOIN SAT_CATALOGOS_OPCIONES CO ON CO.PK_CATALOGO = CS.PK_CATALOGO AND CO.PK1 = CS.PK_OPCION WHERE CS.CVE_SEDE = '" + cve_sede + @"' ORDER BY CS.PK_CATALOGO, CO.FECHA_R DESC" ; ResultSet res = model.db.getTable(sql); Dictionary <string, ValidarTexto> validaciones = new Dictionary <string, ValidarTexto>(); while (res.Next()) { try { ValidarTexto validacion = new ValidarTexto { PkCatalogo = res.GetInt("PK_CATALOGO"), Opcion = res.Get("OPCION"), PkOpcion = res.GetInt("PK_OPCION"), ClaveCatalogo = res.Get("CVE_CATALOGO"), MetodoBusqueda = res.GetInt("METODO_BUSQUEDA"), }; // Se consultan las cadenas para buscar el identificador sql = "SELECT BUSCAR_COMO FROM SAT_CATALOGOS_BUSCAR WHERE PK_CATALOGO=" + validacion.PkCatalogo; ResultSet res_2 = model.db.getTable(sql); while (res_2.Next()) { validacion.BuscarComo.Add(res_2.Get("BUSCAR_COMO")); } // Se consultan las cadenas para buscar los posibles valores de la opcion seleccionada del catalogo sql = "SELECT BUSCAR_COMO FROM SAT_CATALOGOS_OPCIONES_BUSCAR WHERE PK_OPCION=" + validacion.PkOpcion; res_2 = model.db.getTable(sql); while (res_2.Next()) { validacion.ListFrases.Add(res_2.Get("BUSCAR_COMO")); } validaciones.Add(validacion.ClaveCatalogo, validacion); } catch (Exception) { } } return(validaciones); }
public int CadastrarCliente(ClientesDTO dto) { if (dto.ds_Bairro == string.Empty) { throw new ArgumentException("Bairro não pode estar vazio."); } if (dto.ds_Logradouro == string.Empty) { throw new ArgumentException("Logradouro não pode estar vazio."); } if (dto.ds_UF == string.Empty) { throw new ArgumentException("UF não pode estar vazio."); } if (dto.ds_CEP == string.Empty) { throw new ArgumentException("CEP não pode estar vazio."); } ValidarNumero regexNum = new ValidarNumero(); ValidarTexto regexTxt = new ValidarTexto(); regexTxt.ValidarEmail(dto.ds_Email); regexTxt.ValidarNome(dto.nm_Nome); regexNum.ValidarTelefoneFixo(dto.num_Telefone); regexNum.ValidarTelefoneCelular(dto.num_Celular); CPF validar = new CPF(); validar.ValidarCPF(dto.ds_CPF); DESCripto cripto = new DESCripto(); dto.nm_Nome = cripto.Criptografar(Program.chave, dto.nm_Nome); dto.ds_CPF = cripto.Criptografar(Program.chave, dto.ds_CPF); dto.num_Celular = cripto.Criptografar(Program.chave, dto.num_Celular); dto.num_Telefone = cripto.Criptografar(Program.chave, dto.num_Telefone); dto.ds_Email = cripto.Criptografar(Program.chave, dto.ds_Email); ClientesDatabase db = new ClientesDatabase(); int idCliente = db.CadastrarCliente(dto); if (idCliente == 0) { throw new ArgumentException("O cliente não foi cadastrado com sucesso!"); } return(idCliente); }
public int CadastroNovoEmprestimo(tb_emprestimo dto, tb_locatario professor) { try { DateTime ontem = DateTime.Today; ontem = ontem.AddDays(-1); if (dto.dt_devolucao.Day - DateTime.Today.Day < 0) { throw new ArgumentException("Impossivel devolver um livro ontem!"); } ValidarTexto val = new ValidarTexto(); val.ValidarEmail(professor.ds_email); val.ValidarNome(dto.nm_funcionario); val.ValidarNome(professor.nm_locatario); ValidarNumero valN = new ValidarNumero(); valN.ValidarTelefoneCelular(professor.nu_celular); AzureBiblioteca db = new AzureBiblioteca(); tb_locatario data = db.tb_locatario.Where(x => x.nu_cpf == professor.nu_cpf).ToList().Single(); if (data.nm_locatario != null) { dto.tb_locatario_id_locatario = data.id_locatario; return(EmprestimoDB.CadastroNovoEmprestimo(dto)); } return(0); } catch (ArgumentException ex) { System.Windows.Forms.MessageBox.Show($"{ex.Message}", "Biblioteca", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } catch (Exception) { AzureBiblioteca db = new AzureBiblioteca(); int id; db.tb_locatario.Add(professor); id = db.SaveChanges(); dto.tb_locatario_id_locatario = id; return(EmprestimoDB.CadastroNovoEmprestimo(dto)); } return(0); }