private void Btn_ExcluiCargo_Click(object sender, EventArgs e) { if (MessageBox.Show("Deseja realmente excluir ? Essa operação não pode ser desfeita!!", "Confirmação", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string comando = "delete from setor where idcargo = " + Convert.ToString(this.Grid_Setor.CurrentRow.Cells["idcargo"].Value);; SQLFunctions.ExecutaComando(comando); Grid_Cargo.DataSource = SQLFunctions.GetInfos(Consultas.consultaCargo + Edt_IDSetor.Text); } }
private void Btn_Vender_Click(object sender, EventArgs e) { if (CB_Moeda.Text == "") { MessageBox.Show("Seleciona a moeda que deseja operar!"); } else if (Edt_VlrNegociar.Text == "") { MessageBox.Show("Selecione o valor que deseja operar!"); } double quant_obtida = (Convert.ToDouble(Edt_VlrNegociar.Text) / (Convert.ToDouble(Edt_ValorAtual.Text))); if (MessageBox.Show("Deseja vender " + Convert.ToString(quant_obtida) + " " + CB_Moeda.Text + " para obter R$ " + Edt_VlrNegociar.Text, "Confirmação", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Operacao: DataTable pega_carteira = SQLFunctions.GetInfos("SELECT NROCARTEIRA, QUANTIDADE FROM CARTEIRA WHERE IDUSUARIO = " + Session.Instance.UserID + " AND IDMOEDA = " + Convert.ToString(CB_Moeda.SelectedValue)); if (pega_carteira.Rows.Count < 1) { SQLFunctions.ExecutaComando("INSERT INTO CARTEIRA (IDMOEDA,IDUSUARIO,QUANTIDADE) " + "VALUES(" + Convert.ToString(CB_Moeda.SelectedValue) + ", " + Session.Instance.UserID + ", 0)"); goto Operacao; } string carteira = pega_carteira.Rows[0]["NROCARTEIRA"].ToString(); double quantidade = Convert.ToDouble(pega_carteira.Rows[0]["QUANTIDADE"].ToString()); if (quantidade < quant_obtida) { MessageBox.Show("Não é possivel vender! \n Valor a ser negociado maior que saldo disponivel"); } else { string comando = "INSERT INTO Operacao(ValorOperacao, DataHora, IDMoeda, NroCarteira, IDUsuario, Operacao, QuantOperada)" + "VALUES (" + Edt_VlrNegociar.Text + ",'" + Funcoes.FormataDataAmericana(DateTime.Now) + "'," + Convert.ToString(CB_Moeda.SelectedValue) + ", " + carteira + ", " + Session.Instance.UserID + ", 'VENDA'," + Convert.ToString(quant_obtida) + ")"; int i = SQLFunctions.ExecutaComando(comando); if (i == 1) { MessageBox.Show("Ocorreu um erro ao processar a requisição!! \n Aguarde e tente novamente!!"); } else { quant_obtida = quantidade - quant_obtida; SQLFunctions.ExecutaComando("UPDATE CARTEIRA SET QUANTIDADE = " + quant_obtida.ToString() + "WHERE NROCARTEIRA = " + carteira); MessageBox.Show("Transação realizada!"); CB_Moeda.Text = ""; Edt_VlrNegociar.Text = ""; Group_Detalhes.Visible = false; } } } }
private void Btn_SalvaCargo_Click(object sender, EventArgs e) { if (Edt_Setor.Text == "") { MessageBox.Show("Preencha todos os dados!"); } else { string Comando = "INSERT INTO CARGOS(CARGO, IDSETOR) VALUES('" + Edt_Cargo.Text + "','" + Edt_IDSetor.Text + "')"; int i = SQLFunctions.ExecutaComando(Comando); if (i > 0) { MessageBox.Show("Ocorreu um erro ao salvar!"); } Grid_Cargo.DataSource = SQLFunctions.GetInfos(Consultas.consultaCargo + Edt_IDSetor.Text); } }
private void Btn_Salvar_Click(object sender, EventArgs e) { if (Edt_Abrevicao.Text == "") { MessageBox.Show("Preencha a abreviação!"); } else if (Edt_Descricao.Text == "") { MessageBox.Show("Preencha a Descrição!"); } else { string comando = "Insert into Moedas (NomeMoeda, Abreviacao, ValorMercado) " + "Values ('" + Edt_Descricao.Text + "', '" + Edt_Abrevicao.Text + "', 0)"; int i = SQLFunctions.ExecutaComando(comando); if (i > 0) { MessageBox.Show("Ocorreu um erro ao salvar!"); } Grd_Moedas.DataSource = SQLFunctions.GetInfos("select * from moedas"); } }
private void Btn_Salvar_Click(object sender, EventArgs e) { if (Edt_Login.Text == "") { MessageBox.Show("Preencha todos os dados!"); } else if (Edt_Senha.Text == "") { MessageBox.Show("Preencha todos os dados!"); } else if (Edt_Nivel.Text == "") { MessageBox.Show("Preencha todos os dados!"); } else { if (Edt_IDLogin.Text == "") { string val_ativo; if (Edt_Ativo.Checked == true) { val_ativo = "S"; } else { val_ativo = "N"; } string Comando = "INSERT INTO Usuarios (Login, Senha, NivelDeAcesso, Ativo) " + "values ('" + Edt_Login.Text + "','" + Edt_Senha.Text + "','" + Edt_Nivel.Text + "','" + val_ativo + "')"; int i = SQLFunctions.ExecutaComando(Comando); if (i > 0) { MessageBox.Show("Ocorreu um erro ao salvar!"); } try { SqlConnection con = new SqlConnection(Variaveis.conexao); //Cria a variavel de conexão con.Open(); //Abre a conexão { Habilita(VF: false); Btn_Novo.Enabled = true; Btn_Alterar.Enabled = false; Btn_Salvar.Enabled = false; Btn_Cancelar.Enabled = false; Btn_Novo.Focus(); } } catch (Exception ex) //Caso retorne algum erro { MessageBox.Show("Erro: " + ex.ToString()); //Exibe o erro retornado } finally { SqlConnection con = new SqlConnection(Variaveis.conexao); //Cria a variavel de conexão con.Close(); //Fecha a conexão } } else { string val_ativo; if (Edt_Ativo.Checked == true) { val_ativo = "S"; } else { val_ativo = "N"; } string comando = "UPDATE Usuarios SET IDFuncionario = '" + Edt_IDFuncionario.Text + "', Login = '******', Senha = '" + Edt_Senha.Text + "', NivelDeAcesso = '" + Edt_Nivel.Text + "', Ativo = '" + val_ativo + "' WHERE Login = '******'"; int i = SQLFunctions.ExecutaComando(comando); if (i > 0) { MessageBox.Show("Ocorreu um erro ao salvar!"); } Habilita(VF: false); Btn_Novo.Enabled = true; Btn_Alterar.Enabled = false; Btn_Salvar.Enabled = false; Btn_Cancelar.Enabled = false; Btn_Novo.Focus(); } } }