private async void loginLoad() { try { string URL2 = "http://localhost:3000/usuarios"; using (var client2 = new HttpClient()) { HttpResponseMessage response2 = await client2.GetAsync(URL2); if (response2.IsSuccessStatusCode) { var logins = await response2.Content.ReadAsStringAsync(); //MessageBox.Show("DEBUG " + logins); JArray sizes = JArray.Parse(logins); dynamic data = JObject.Parse(sizes[0].ToString()); int a = 0; for (int i = 0; i < sizes.Count(); i++) { if (sizes[i]["email"].ToString() == textBox1.Text && sizes[i]["passWorld"].ToString() == textBox2.Text) { //MessageBox.Show(sizes.Count().ToString()); loadForm1(1, sizes[i]["nome"].ToString()); break; } else { a += 1; } } if (a == sizes.Count()) { MessageBox.Show("E-mail ou senha incorretos", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } } catch { this.Hide(); var erro = new ErroConexao(); erro.Closed += (s, args) => this.Close(); erro.Show(); } }
private async void GetUserId(string decide) { try { string URL = "http://localhost:3000/usuarios/" + decide.ToString(); using (var client = new HttpClient()) { HttpResponseMessage response = await client.GetAsync(URL); if (response.IsSuccessStatusCode) { // MessageBox.Show("DEBUG 1 " + await response.Content.ReadAsStringAsync()); var FuncionarioJsonString = await response.Content.ReadAsStringAsync(); JArray sizes = JArray.Parse(FuncionarioJsonString); dynamic data = JObject.Parse(sizes[0].ToString()); string data2 = (string)data["nome"]; string data3 = (string)data["email"]; string data4 = (string)data["senha"]; // MessageBox.Show("DEBUG" + FuncionarioJsonString); textBox1.Text = data2; textBox2.Text = data3; textBox3.Text = data4; var json = JsonConvert.DeserializeObject <funcionarioFiltrado[]>(FuncionarioJsonString); } else { MessageBox.Show("Erro ao montar o objeto", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } catch (Exception e) { //MessageBox.Show("DEBUG " + e); this.Hide(); var erro = new ErroConexao(); erro.Closed += (s, args) => this.Close(); erro.Show(); } }
private async void insertUser() { string Nome = textBox1.Text; string Email = textBox2.Text; string Senha = textBox3.Text; string SenhaConfirmada = textBox4.Text; if (Nome == "") { MessageBox.Show("O campo nome é obrigatório", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Information); } if (Email == "") { MessageBox.Show("O campo Email é obrigatório", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Information); } if (!Email.Contains("@")) { MessageBox.Show("digite um email válido", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Information); } if (Senha == "") { MessageBox.Show("O campo Senha é obrigatório", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Information); } if (Senha.Length < 6) { MessageBox.Show("O campo Senha deve ter mais de 6 dígitos", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Information); } if (Senha != SenhaConfirmada) { MessageBox.Show("As senhas não conferem", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { string URL = "http://localhost:3000/usuarios"; try { createUsuario create = new createUsuario(); create.nome = Nome; create.email = Email; create.passWorld = Senha; using (var client = new HttpClient()) { var serializedUsuario = JsonConvert.SerializeObject(create); //MessageBox.Show("DEBUG " + serializedUsuario); var content = new StringContent(serializedUsuario, Encoding.UTF8, "application/json"); //MessageBox.Show("DEBUG " + content); var result = await client.PostAsync(URL, content); //MessageBox.Show("DEBUG " + result); if (result.IsSuccessStatusCode) { DialogResult dialogResult = MessageBox.Show("Usuário Cadastrado com sucesso", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Question); if (dialogResult == DialogResult.OK) { this.Close(); } } } } catch { this.Hide(); var erro = new ErroConexao(); erro.Closed += (s, args) => this.Close(); erro.Show(); } } }
private async void GetEmployees(string id) { try { string URL = "http://localhost:3000/funcionarios/" + id.ToString(); using (var client = new HttpClient()) { using (var response = await client.GetAsync(URL)) { if (response.IsSuccessStatusCode) { var FuncionarioJsonString = await response.Content.ReadAsStringAsync(); // MessageBox.Show("DEBUG " + await response.Content.ReadAsStringAsync()); JArray sizes = JArray.Parse(FuncionarioJsonString); dynamic data = JObject.Parse(sizes[0].ToString()); string data1 = (string)data["matricula"]; string data2 = (string)data["ctps"]; string data3 = (string)data["admissao"]; string data4 = (string)data["demissao"]; if (data4 == null) { data4 = "Funcionário Ativo"; } string data5 = (string)data["sexo"]; string data6 = (string)data["numero"]; string data7 = (string)data["logradouro"]; string data8 = (string)data["bairro"]; string data9 = (string)data["cidade"]; string data10 = (string)data["uf"]; label1.Text = data1; label3.Text = data2; label4.Text = data3; label5.Text = data4; label2.Text = data5; label13.Text = data6; label15.Text = data7; label17.Text = data8; label18.Text = data9; label21.Text = data10; } else { MessageBox.Show("Não foi possoível conectat a base de dados", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } catch { this.Hide(); var erro = new ErroConexao(); erro.Closed += (s, args) => this.Close(); erro.Show(); } }
private async void GetAllusuarios() { this.dataGridView1.Columns.Clear(); try { string URL = "http://localhost:3000/usuarios"; using (var client = new HttpClient()) { using (var response = await client.GetAsync(URL)) { if (response.IsSuccessStatusCode) { var usuariosJsonString = await response.Content.ReadAsStringAsync(); // MessageBox.Show("DEBUG " + funcoesJsonString); //textBox1.Text = await response.Content.ReadAsStringAsync(); dataGridView5.DataSource = JsonConvert.DeserializeObject <getAllUsuarios[]>(usuariosJsonString).ToList(); } else { MessageBox.Show("Não foi possivel conectar a base de dados" + response.StatusCode); } } } } catch { this.Hide(); var erro = new ErroConexao(); erro.Closed += (s, args) => this.Close(); erro.Show(); } DataGridViewButtonColumn button = new DataGridViewButtonColumn(); { button.Name = "APAGAR"; button.HeaderText = "APAGAR"; button.Text = "APAGAR"; button.FlatStyle = FlatStyle.Flat; button.DefaultCellStyle.BackColor = Color.Red; button.DefaultCellStyle.ForeColor = Color.White; button.UseColumnTextForButtonValue = true; this.dataGridView5.Columns.Add(button); } DataGridViewButtonColumn button2 = new DataGridViewButtonColumn(); { button2.Name = "EDITAR"; button2.HeaderText = "EDITAR"; button2.Text = "EDITAR"; button2.FlatStyle = FlatStyle.Flat; button2.DefaultCellStyle.BackColor = Color.Blue; button2.DefaultCellStyle.ForeColor = Color.White; button2.UseColumnTextForButtonValue = true; this.dataGridView5.Columns.Add(button2); } DataGridViewButtonColumn button3 = new DataGridViewButtonColumn(); { button3.Name = "DETALHAR"; button3.HeaderText = "DETALHAR"; button3.Text = "DETALHAR"; button3.FlatStyle = FlatStyle.Flat; button3.DefaultCellStyle.BackColor = Color.Blue; button3.DefaultCellStyle.ForeColor = Color.White; button3.UseColumnTextForButtonValue = true; this.dataGridView5.Columns.Add(button3); } }
private async void GetEmployeesId(string id) { try { string URL = "http://localhost:3000/funcionarios/" + id.ToString(); using (var client = new HttpClient()) { HttpResponseMessage response = await client.GetAsync(URL); if (response.IsSuccessStatusCode) { // MessageBox.Show("DEBUG 1 " + await response.Content.ReadAsStringAsync()); var FuncionarioJsonString = await response.Content.ReadAsStringAsync(); JArray sizes = JArray.Parse(FuncionarioJsonString); dynamic data = JObject.Parse(sizes[0].ToString()); string data2 = (string)data["matricula"]; string data3 = (string)data["cpf"]; string data4 = (string)data["ctps"]; string data5 = (string)data["admissao"]; string data6 = (string)data["demissao"]; string data7 = (string)data["sexo"]; string data8 = (string)data["numero"]; string data9 = (string)data["logradouro"]; string data10 = (string)data["bairro"]; string data11 = (string)data["cidade"]; string data12 = (string)data["uf"]; string data13 = (string)data["id"]; string data14 = (string)data["nome"]; string data15 = (string)data["setorId"]; string data16 = (string)data["setorNome"]; string data17 = (string)data["funcaoId"]; string data18 = (string)data["funcaoNome"]; textBox10.Text = data2; maskedTextBox1.Text = data3; textBox13.Text = data4; textBox14.Text = data5; textBox15.Text = data6; comboBox1.Text = data7; textBox16.Text = data8; textBox17.Text = data9; textBox18.Text = data10; textBox19.Text = data11; textBox2.Text = data12; comboBox2.Text = data13 + " " + data14; comboBox3.Text = data15 + " " + data16; comboBox4.Text = data17 + " " + data18; var json = JsonConvert.DeserializeObject <funcionarioFiltrado[]>(FuncionarioJsonString); } else { MessageBox.Show("Erro ao montar o objeto", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } catch (Exception e) { //MessageBox.Show("DEBUG " + e); this.Hide(); var erro = new ErroConexao(); erro.Closed += (s, args) => this.Close(); erro.Show(); } }