// SALVA/EDITA OS DADOS NO BANCO DE DADOS protected void Salvar_Click(object sender, EventArgs e) { try { string comando = ""; if (Codigo.Text == "") { // 2. CRIA A STRING DE COMANDO SQL PARA INSEIR UMA LINHA comando = "INSERT INTO Computadores(Nome,Endereco,Anotacoes) VALUES('" + Nome.Text + "','" + Endereco.Text + "','" + Anotacoes.Text + "');"; } else { // 2. COMANDO PARA EDITAR A LINHA SELECIONADA comando = "UPDATE Computadores SET Nome='" + Nome.Text + "',Endereco='" + Endereco.Text + "',Anotacoes='" + Anotacoes.Text + "' WHERE Codigo=" + Codigo.Text; } // 3. ENVIAR O COMANDO AO BANCO DE DADOS AppDatabase.OleDBTransaction db = new AppDatabase.OleDBTransaction(); db.ConnectionString = conexao; db.Query(comando); ExibirComputadores(); } catch (Exception ex) { Mensagem.Text = "Houve uma falha ao gravar o registro; " + ex.Message; App_Code.RecoverExceptions re = new App_Code.RecoverExceptions(); re.SaveException(ex); } }
void RecuperarDados() { try { string comando = "SELECT Codigo,Nome,Descricao,Data_Agendamento AS Data,Hora_Agendamento AS Hora FROM Pedido WHERE Status='Agendado' ORDER BY Data_Agendamento,Hora_Agendamento DESC"; AppDatabase.OleDBTransaction db = new AppDatabase.OleDBTransaction(); db.ConnectionString = conexao; System.Data.DataTable tb = new System.Data.DataTable(); tb = (System.Data.DataTable)db.Query(comando); Pedido.DataSource = tb; Pedido.DataBind(); Pedido.Dispose(); ControleCotacao.Visible = false; this.Master.MasterForm = false; Limpar.Visible = false; } catch (Exception ex) { Erro.Text = "Houve uma falha inesperada"; RecoverExceptions re = new RecoverExceptions(); re.SaveException(ex); } }
protected void Salvar_Click(object sender, EventArgs e) { try { if (Protocolo.Text.Trim() == "" || DataCartorio.Text.Trim() == "") { Motivo.Text = "Preencha os dois campos"; } else { TimeSpan ts = new TimeSpan(3, 0, 0); string comando = "UPDATE Pedido SET Status='Cartorio Protocolado',Atual_Status='" + DateTime.UtcNow.Subtract(ts).ToString() + "',Protocolo_Cartorio='" + Protocolo.Text + "',Data_Cartorio='" + DataCartorio.Text + "' WHERE Codigo=" + Codigo.Text; AppDatabase.OleDBTransaction db = new AppDatabase.OleDBTransaction(); db.ConnectionString = conexao; db.Query(comando); Erro.Text = "Protocolado com sucesso"; RecuperarDados(); } } catch (Exception ex) { ADSLIB2020.RecoverExceptions re = new ADSLIB2020.RecoverExceptions(); re.SaveException(ex); Erro.Text = "Houve uma falha inesperada"; } }
void RecuperarDados() { try { string comando = "SELECT Codigo,Nome,Descricao,Data_Pagamento AS Data FROM Pedido WHERE Status='Aguardando Pagamento' ORDER BY Data_Pagamento ASC"; AppDatabase.OleDBTransaction db = new AppDatabase.OleDBTransaction(); db.ConnectionString = conexao; System.Data.DataTable tb = new System.Data.DataTable(); tb = (System.Data.DataTable)db.Query(comando); Pedido.DataSource = tb; Pedido.DataBind(); Pedido.Dispose(); ControleCotacao.Visible = false; this.Master.MasterForm = false; Pergunta.Visible = false; Valor.Text = ""; Valor.Visible = false; Salvar.Visible = false; Sim.Visible = true; Nao.Visible = true; } catch (Exception ex) { RecoverExceptions re = new RecoverExceptions(); re.SaveException(ex); Erro.Text = "Houve uma falha inesperada."; } }
protected void Funcionarios_SelectedIndexChanged(object sender, EventArgs e) { try { Codigo.Text = Funcionarios.SelectedRow.Cells[1].Text; string comando = "SELECT * FROM Funcionarios WHERE Codigo=" + Codigo.Text; AppDatabase.OleDBTransaction db = new AppDatabase.OleDBTransaction(); db.ConnectionString = conexao; System.Data.DataTable tb = (System.Data.DataTable)db.Query(comando); if (tb.Rows.Count == 1) { Nome.Text = tb.Rows[0]["Nome"].ToString(); Login.Text = tb.Rows[0]["Login"].ToString(); Senha.Text = tb.Rows[0]["Senha"].ToString(); Anotacoes.Text = tb.Rows[0]["Anotacoes"].ToString(); Excluir.Visible = true; Limpar.Visible = true; codfunc.Visible = true; } } catch (Exception ex) { Codigo.Text = "Houve uma falha"; RecoverExceptions re = new RecoverExceptions(); re.SaveException(ex); } }
protected void RecuperarDados() { try { string comando = "SELECT * FROM Funcionarios ORDER BY Nome ASC"; System.Data.DataTable tb = new System.Data.DataTable(); AppDatabase.OleDBTransaction db = new AppDatabase.OleDBTransaction(); db.ConnectionString = conexao; tb = (System.Data.DataTable)db.Query(comando); Funcionarios.DataSource = tb; Funcionarios.DataBind(); Funcionarios.Dispose(); Codigo.Text = ""; Nome.Text = ""; Login.Text = ""; Senha.Text = ""; Anotacoes.Text = ""; Excluir.Visible = false; Limpar.Visible = false; codfunc.Visible = false; Mensagem.Text = ""; } catch (Exception ex) { Mensagem.Text = "Houve uma falha inesperada. Por Favor, tente novamente mais tarde"; RecoverExceptions re = new RecoverExceptions(); re.SaveException(ex); } }
protected void Buscar_Click(object sender, EventArgs e) { try { Erro.Text = ""; if (Pesquisa.Text.Trim() == "") { Erro.Text = "Insira um valor no campo pesquisa"; } else { string comando = "SELECT Codigo,Nome,Descricao FROM Pedido WHERE Status='Aguardando Cotacao' AND Nome + Descricao LIKE '%" + Pesquisa.Text + "%'"; AppDatabase.OleDBTransaction db = new AppDatabase.OleDBTransaction(); db.ConnectionString = conexao; System.Data.DataTable tb = new System.Data.DataTable(); tb = (System.Data.DataTable)db.Query(comando); Pedido.DataSource = tb; Pedido.DataBind(); Pedido.Dispose(); Limpar_Busca.Visible = true; } } catch (Exception ex) { Erro.Text = "Houve uma falha inesperada"; RecoverExceptions re = new RecoverExceptions(); re.SaveException(ex); } }
protected void RecuperarDados() { try { string comando = "SELECT Codigo,Nome,Descricao,Atual_Status FROM Pedido WHERE Status='Aguardando Nota' ORDER BY Atual_Status ASC"; AppDatabase.OleDBTransaction db = new AppDatabase.OleDBTransaction(); db.ConnectionString = conexao; System.Data.DataTable tb = new System.Data.DataTable(); tb = (System.Data.DataTable)db.Query(comando); Pedido.DataSource = tb; Pedido.DataBind(); Pedido.Dispose(); Pergunta.Visible = false; ControleCotacao.Visible = false; Aviso.Visible = false; this.Master.MasterForm = false; Limpar.Visible = false; } catch (Exception ex) { RecoverExceptions re = new RecoverExceptions(); re.SaveException(ex); Erro.Text = "Houve uma falha inesperada."; } }
protected void Enviar_Click(object sender, EventArgs e) { try { if (NovaDataPagamento.Text.Length < 10 && NotaFiscal.Text.Trim() == "") { Aviso.Visible = true; } else { TimeSpan ts = new TimeSpan(3, 0, 0); AppDatabase.OleDBTransaction db = new AppDatabase.OleDBTransaction(); db.ConnectionString = conexao; string comando = "UPDATE Pedido SET Status='Agendar Pagamento', Atual_Status='" + DateTime.UtcNow.Subtract(ts).ToString() + "', Nota_Fiscal='" + NotaFiscal.Text + "', Data_Pagamento='" + NovaDataPagamento.Text + "' WHERE Codigo=" + Codigo.Text; db.Query(comando); Erro.Text = "Nota salva com sucesso"; RecuperarDados(); } } catch (Exception ex) { Erro.Text = "Houve uma falha inesperada"; RecoverExceptions re = new RecoverExceptions(); re.SaveException(ex); } }
protected void Agendar_Click(object sender, EventArgs e) { try { if (DataAgendamento.Text.Trim() == "" || HoraAgendamento.Text.Trim() == "") { ErroAgendamento.InnerText = "Preencha corretamente os campos"; } else { TimeSpan ts = new TimeSpan(3, 0, 0); string comando = "UPDATE Pedido SET Status=" + "'Agendado'" + ",Atual_Status='" + DateTime.UtcNow.Subtract(ts).ToString() + "',Data_Agendamento='" + DataAgendamento.Text + "',Hora_Agendamento='" + HoraAgendamento.Text + "' WHERE Codigo=" + Codigo.Text; AppDatabase.OleDBTransaction db = new AppDatabase.OleDBTransaction(); db.ConnectionString = conexao; db.Query(comando); Erro.Text = "Coleta Agendada com sucesso"; RecuperarDados(); } } catch (Exception ex) { Erro.Text = "Houve uma falha inesperada"; RecoverExceptions re = new RecoverExceptions(); re.SaveException(ex); } }
protected void ExcluirCot_Click(object sender, EventArgs e) { if (MotivoSelect.SelectedIndex == 0) { ErroMotivo.Text = "Informe o motivo"; } else { try { TimeSpan ts = new TimeSpan(3, 0, 0); string comando = "INSERT INTO CotNaoAceitas(Motivo,Razao,Data) VALUES('" + MotivoSelect.SelectedIndex.ToString() + "','" + "Cotacao recusada" + "','" + DateTime.UtcNow.Subtract(ts).ToString() + "');"; string commando = "DELETE * FROM Pedido WHERE Codigo=" + Codigo.Text + ";"; AppDatabase.OleDBTransaction db = new AppDatabase.OleDBTransaction(); db.ConnectionString = conexao; db.Query(comando); db.Query(commando); Erro.Text = "Operação feita com sucesso"; RecuperarDados(); } catch (Exception ex) { Codigo.Text = "Houve uma falha inesperada"; RecoverExceptions re = new RecoverExceptions(); re.SaveException(ex); } } }
protected void Enviar_Click(object sender, EventArgs e) { try { if (Boleto.Text.Trim() == "") { Aviso.Visible = true; } else { TimeSpan ts = new TimeSpan(3, 0, 0); string comando = "UPDATE Pedido SET Status='Aguardando Pagamento',Atual_Status='" + DateTime.UtcNow.Subtract(ts).ToString() + "',Boleto='" + Boleto.Text + "' WHERE Codigo=" + Codigo.Text; AppDatabase.OleDBTransaction db = new AppDatabase.OleDBTransaction(); db.ConnectionString = conexao; db.Query(comando); Erro.Text = "Número de boleto enviado com sucesso."; RecuperarDados(); } } catch (Exception ex) { Erro.Text = "Houve uma falha inesperada."; RecoverExceptions re = new RecoverExceptions(); re.SaveException(ex); } }
protected void Pedido_SelectedIndexChanged(object sender, EventArgs e) { try { Codigo.Text = Pedido.SelectedRow.Cells[1].Text; this.Master.Codigo = Codigo.Text.ToString(); string comando = "SELECT * FROM Pedido WHERE Codigo=" + Codigo.Text; AppDatabase.OleDBTransaction db = new AppDatabase.OleDBTransaction(); db.ConnectionString = conexao; System.Data.DataTable tb = new System.Data.DataTable(); tb = (System.Data.DataTable)db.Query(comando); CodCot.Text = "Código da cotação: "; Nome.Text = "Nome do Cliente: "; Data.Text = "Data do Pedido: "; Status.Text = "Status do Pedido: "; AtualStatus.Text = "Data de atualização do status: "; if (tb.Rows.Count == 1) { Nome.Text += tb.Rows[0]["Nome"].ToString(); Data.Text += tb.Rows[0]["Data"].ToString(); Status.Text += tb.Rows[0]["Status"].ToString(); AtualStatus.Text += tb.Rows[0]["Atual_Status"].ToString(); this.Master.MasterObservacao = tb.Rows[0]["Observacao"].ToString(); this.Master.MasterNome = tb.Rows[0]["Nome"].ToString(); this.Master.MasterEmail = tb.Rows[0]["Email"].ToString(); this.Master.MasterTelefone = tb.Rows[0]["Telefone"].ToString(); this.Master.MasterComprimento = tb.Rows[0]["Comprimento"].ToString(); this.Master.MasterLargura = tb.Rows[0]["Largura"].ToString(); this.Master.MasterAltura = tb.Rows[0]["Altura"].ToString(); this.Master.MasterPeso = tb.Rows[0]["Peso"].ToString(); this.Master.MasterDescricao = tb.Rows[0]["Descricao"].ToString(); this.Master.MasterCepColeta = tb.Rows[0]["CEP_Coleta"].ToString(); this.Master.MasterCidadeColeta = tb.Rows[0]["Cidade_Coleta"].ToString(); this.Master.MasterRuaColeta = tb.Rows[0]["Rua_Coleta"].ToString(); this.Master.MasterNumeroColeta = tb.Rows[0]["Numero_Coleta"].ToString(); this.Master.MasterBairroColeta = tb.Rows[0]["Bairro_Coleta"].ToString(); this.Master.MasterEstadoColeta = tb.Rows[0]["Estado_Coleta"].ToString(); this.Master.MasterCepEntrega = tb.Rows[0]["CEP_Entrega"].ToString(); this.Master.MasterCidadeEntrega = tb.Rows[0]["Cidade_Entrega"].ToString(); this.Master.MasterRuaEntrega = tb.Rows[0]["Rua_Entrega"].ToString(); this.Master.MasterNumeroEntrega = tb.Rows[0]["Numero_Entrega"].ToString(); this.Master.MasterBairroEntrega = tb.Rows[0]["Bairro_Entrega"].ToString(); this.Master.MasterEstadoEntrega = tb.Rows[0]["Estado_Entrega"].ToString(); this.Master.MasterForm = true; ControleCotacao.Visible = true; Pergunta.Visible = true; Limpar.Visible = true; } } catch (Exception ex) { Erro.Text = "Houve uma falha inesperada"; RecoverExceptions re = new RecoverExceptions(); re.SaveException(ex); } }
protected void RecuperarDados() { try { string comando = "SELECT Codigo, Nome, Descricao,Data FROM Pedido WHERE Status='Aguardando Cotacao' ORDER BY Codigo ASC"; //DATATABLE System.Data.DataTable tb = new System.Data.DataTable(); //CONEXAO AO BANCO DE DADOS, ENVIO DOS COMANDOS SQL AppDatabase.OleDBTransaction db = new AppDatabase.OleDBTransaction(); db.ConnectionString = conexao; tb = (System.Data.DataTable)db.Query(comando); Pedido.DataSource = tb; Pedido.DataBind(); tb.Dispose(); Pesquisa.Text = ""; Limpar.Visible = false; Limpar_Busca.Visible = false; Responder.Visible = false; EnviarMsg.Visible = false; editor.Visible = false; ControleCotacao.Visible = false; this.Master.MasterForm = false; } catch (Exception ex) { Erro.Text = "Houve um erro ao carregar os pedidos"; RecoverExceptions re = new RecoverExceptions(); re.SaveException(ex); } }
protected void Salvar_Click(object sender, EventArgs e) { AppDatabase.OleDBTransaction ole = new AppDatabase.OleDBTransaction(); ole.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("~/Dados/Cadastro.accdb") + ";Persist Security Info=false"; ole.Query("UPDATE Clientes SET nome='" + NomeCliente.Text + "', Email='" + EmailCliente.Text + "', Telefone='" + TelefoneCliente.Text + "' WHERE CODIGO=" + GridView1.SelectedRow.Cells[1].Text); LoadGrid(); }
protected void Excluir_Click(object sender, EventArgs e) { string sql = "DELETE FROM Computadores WHERE Codigo = " + Codigo.Value; // CONECTA NO BANCO DE DADOS db = new ConexaoDB().GetConnection(); db.Query(sql); LimparControles(); }
protected void Enviar_Click(object sender, EventArgs e) { try { if (NomeLogin.Text.Trim() == "") { Mensagem.Text = "Preencha o campo Login"; } else if (Senha.Text.Trim() == "") { Mensagem.Text = "Preencha o campo Senha"; } else { string comando = "SELECT * FROM Funcionarios WHERE Login='******'AND Senha='" + Senha.Text + "';"; AppDatabase.OleDBTransaction db = new AppDatabase.OleDBTransaction(); db.ConnectionString = conexao; System.Data.DataTable tb = (System.Data.DataTable)db.Query(comando); if (tb.Rows.Count == 1) { Session["Codigo"] = tb.Rows[0]["Codigo"].ToString(); Session["Nome"] = tb.Rows[0]["Nome"].ToString(); // AUTENTICAÇÃO DE USUARIO FormsAuthentication.Initialize(); //Define os dados do ticket de autenticação FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, Session["Nome"].ToString(), DateTime.Now, DateTime.Now.AddMinutes(30), false, Session["Nome"].ToString(), FormsAuthentication.FormsCookiePath); // Grava o ticket no cookie de autenticação Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket))); // redirecionar para a Dasboard Response.Redirect("~/Pages/Admin/Dashboard.aspx"); } else { Mensagem.Text = "Dados Inválidos"; } } } catch (ThreadAbortException) { // IGNORE: this is normal behavior for Redirect method } catch (Exception ex) { Mensagem.Text = "Houve uma falha inesperada. Por Favor, tente novamente mais tarde"; RecoverExceptions re = new RecoverExceptions(); re.SaveException(ex); } }
protected void ExecutaPing() { string sql = "SELECT Nome, Endereco FROM Computadores ORDER BY Nome"; db = new ConexaoDB().GetConnection(); DataTable tb = (DataTable)db.Query(sql); Computadores.DataSource = tb; Computadores.DataBind(); }
// 1. SELECIONA TODOS OS REGISTROS DA TABELA PARA EXIBIR NO GRID protected void ExibirComputadores() { string sql = "SELECT Codigo,Nome,Endereco FROM Computadores ORDER BY Nome;"; // faz a conexão e envia o comando SQL db = new ConexaoDB().GetConnection(); DataTable tb = (DataTable)db.Query(sql); ListaComputadores.DataSource = tb; ListaComputadores.DataBind(); }
protected void Excluir_Click(object sender, EventArgs e) { // 2. CRIA O COMANDO PARA EXCLUIR O REGISTRO string comando = "DELETE FROM Computadores WHERE Codigo=" + Codigo.Text; // 3. ENVIAR O COMANDO AO BANCO DE DADOS AppDatabase.OleDBTransaction db = new AppDatabase.OleDBTransaction(); db.ConnectionString = conexao; db.Query(comando); ExibirComputadores(); }
protected void LoadGrid() { string conexao = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("~/Dados/Cadastro.accdb") + ";Persist Security Info=false"; AppDatabase.OleDBTransaction ole = new AppDatabase.OleDBTransaction(); ole.ConnectionString = conexao; DataTable TB = (DataTable)ole.Query("Select * FROM Clientes ;"); GridView1.DataSource = TB; GridView1.DataBind(); }
protected void Gravar_Click(object sender, EventArgs e) { //string de conexao com o banco de dados "Access provedor Microsoft.ACE.OLEDB.12.0" string conexao = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("~/Dados/Cadastro.accdb") + ";Persist Security Info=false"; //Query SQL para inserir um registro string comando = "INSERT INTO Clientes(Nome,Email,Telefone) VALUES('" + NomeCliente.Text + "','" + EmailCliente.Text + "','" + TelefoneCliente.Text + "');"; AppDatabase.OleDBTransaction ole = new AppDatabase.OleDBTransaction(); ole.ConnectionString = conexao; ole.Query(comando); }
protected void Buscar_Click(object sender, EventArgs e) { string comando = "SELECT Codigo,Nome,Endereco FROM Computadores WHERE Nome+' '+Endereco LIKE '%" + BuscarComputador.Text + "%'ORDER BY Nome;"; AppDatabase.OleDBTransaction db = new AppDatabase.OleDBTransaction(); db.ConnectionString = conexao; System.Data.DataTable tb = (System.Data.DataTable)db.Query(comando); Computadores.DataSource = tb; Computadores.DataBind(); tb.Dispose(); CancelarBuscar.Visible = true; }
protected void Salvar_Click(object sender, EventArgs e) { try { AppDatabase.OleDBTransaction db = new AppDatabase.OleDBTransaction(); db.ConnectionString = conexao; TimeSpan ts = new TimeSpan(3, 0, 0); string comando = string.Empty; if (MotivoList.SelectedIndex == 1) { comando = "UPDATE Pedido SET Status='Aguardando Nota',Atual_Status='" + DateTime.UtcNow.Subtract(ts).ToString() + "' WHERE Codigo=" + Codigo.Text; db.Query(comando); RecuperarDados(); Erro.Text = "Coleta voltou para emissão de nota."; } else if (Valor.Text.Trim() == "") { Aviso.Visible = true; } else if (MotivoList.SelectedIndex == 2) { comando = "UPDATE Pedido SET Status='Calote',Atual_Status='" + DateTime.UtcNow.Subtract(ts).ToString() + "',Valor='" + Valor.Text + "' WHERE Codigo=" + Codigo.Text; db.Query(comando); RecuperarDados(); Erro.Text = "Coleta perdoada."; } else if (MotivoList.SelectedIndex == 3) { comando = "UPDATE Pedido SET Status='Cartorio',Atual_Status='" + DateTime.UtcNow.Subtract(ts).ToString() + "',Valor='" + Valor.Text + "' WHERE Codigo=" + Codigo.Text; db.Query(comando); RecuperarDados(); Erro.Text = "Coleta movida para cartório."; } else { comando = "UPDATE Pedido SET Status='Coleta Finalizada',Atual_Status='" + DateTime.UtcNow.Subtract(ts).ToString() + "',Valor='" + Valor.Text + "' WHERE Codigo=" + Codigo.Text; db.Query(comando); RecuperarDados(); Erro.Text = "Coleta Finalizada"; } } catch (Exception ex) { RecoverExceptions re = new RecoverExceptions(); re.SaveException(ex); Erro.Text = "Houve uma falha inesperada."; } }
protected void grid(object sender, EventArgs e) { AppDatabase.OleDBTransaction ole = new AppDatabase.OleDBTransaction(); ole.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("~/Dados/Cadastro.accdb") + ";Persist Security Info=false"; DataTable TB = (DataTable)ole.Query("Select * FROM Clientes WHERE CODIGO=" + GridView1.SelectedRow.Cells[1].Text + ";"); if (TB.Rows.Count == 1) { NomeCliente.Text = TB.Rows[0]["Nome"].ToString(); EmailCliente.Text = TB.Rows[0]["Email"].ToString(); TelefoneCliente.Text = TB.Rows[0]["Telefone"].ToString(); } }
protected void Salvar_Click(object sender, EventArgs e) { try { if (Nome.Text.Trim() == "") { Mensagem.Text = "Preencha o campo Nome"; } else if (Login.Text.Trim() == "") { Mensagem.Text = "Preencha o campo Login"; } else if (Senha.Text.Trim() == "") { Mensagem.Text = "Preencha o campo Senha"; } else if (Anotacoes.Text.Trim() == "") { Mensagem.Text = "Preencha o campo Anotações"; } else if (LoginExiste(Login.Text.Trim()) == true) { Mensagem.Text = "Este login já existe"; } else { string comando = ""; if (Codigo.Text == "") { comando = "INSERT INTO Funcionarios(Nome,Login,Senha,Anotacoes) VALUES('" + Nome.Text + "','" + Login.Text + "','" + Senha.Text + "','" + Anotacoes.Text + "');"; } else { comando = "UPDATE Funcionarios SET Nome='" + Nome.Text + "',Login='******',Senha='" + Senha.Text + "',Anotacoes='" + Anotacoes.Text + "' WHERE Codigo=" + Codigo.Text + ";"; } AppDatabase.OleDBTransaction db = new AppDatabase.OleDBTransaction(); db.ConnectionString = conexao; db.Query(comando); RecuperarDados(); } } catch (Exception ex) { Mensagem.Text = "Houve uma falha inesperada. Por Favor, tente novamente mais tarde"; RecoverExceptions re = new RecoverExceptions(); re.SaveException(ex); } }
protected void Excluir_Click(object sender, EventArgs e) { AppDatabase.OleDBTransaction ole = new AppDatabase.OleDBTransaction(); ole.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("~/Dados/Cadastro.accdb") + ";Persist Security Info=false"; if (NomeCliente.Text.Trim() != "" && EmailCliente.Text.Trim() != "") { ole.Query("Delete FROM Clientes WHERE CODIGO=" + GridView1.SelectedRow.Cells[1].Text + ";"); } NomeCliente.Text = ""; EmailCliente.Text = ""; TelefoneCliente.Text = ""; LoadGrid(); }
// EXIBE OS DADOS NO GRIDVIEW protected void ExibirComputadores() { string comando = "SELECT Codigo,Nome,Endereco FROM Computadores ORDER BY Nome;"; AppDatabase.OleDBTransaction db = new AppDatabase.OleDBTransaction(); db.ConnectionString = conexao; System.Data.DataTable tb = new System.Data.DataTable(); tb = (System.Data.DataTable)db.Query(comando); Computadores.DataSource = tb; Computadores.DataBind(); tb.Dispose(); }
protected void EnviarMsg_Click(object sender, EventArgs e) { try { if (Resgate.Value == "") { Erro.Text = "A mensagem não pode ser vazia"; } else { string comando = "UPDATE Pedido SET Status=" + "'Aguardando Resposta'" + ",Atual_Status='" + DateTime.Now.ToString() + "' Where Codigo=" + Codigo.Text; AppDatabase.OleDBTransaction db = new AppDatabase.OleDBTransaction(); db.ConnectionString = conexao; db.Query(comando); /* * MailMessage email = new MailMessage(); * SmtpClient smtp = new SmtpClient(); * * email.Subject = "Cotação " + Nome.Text; * email.To.Add(Email.Text); * MailAddress from = new MailAddress("*****@*****.**"); * email.From = from; * email.Body = "Olá, " + Nome.Text + "\n"; * email.Body = Resgate.Value; * email.IsBodyHtml = false; * * // PASSO 2 - ENVIAR A MENSAGEM POR SMTP (SEND EMAIL TRANSFER PROTOCOL) * * smtp.Host = "smtp.live.com"; * smtp.Port = 587; * smtp.EnableSsl = true; * smtp.Credentials = new NetworkCredential("*****@*****.**", "suasenha"); * smtp.Send(email); */ Erro.Text = "Mensagem enviada com sucesso."; RecuperarDados(); } } catch (Exception ex) { RecoverExceptions re = new RecoverExceptions(); re.SaveException(ex); Erro.Text = "Houve uma falha inesperada.Por Favor tente mais tarde"; } }
protected void Entrar_Click(object sender, EventArgs e) { if (login.Text.Trim() == "") { Mensagem.Text = "Dados Invalidos."; } else if (Senha.Text.Trim() == "") { Mensagem.Text = "Dados Invalidos."; } else { string comando = "SELECT * FROM Usuarios WHERE Login='******' AND Senha='" + Senha.Text + "';"; AppDatabase.OleDBTransaction db = new AppDatabase.OleDBTransaction(); db.ConnectionString = conexao; System.Data.DataTable tb = (System.Data.DataTable)db.Query(comando); if (tb.Rows.Count == 1) { // USUÁRIO FOI ENCONTRADO Session["Codigo"] = tb.Rows[0]["Codigo"].ToString(); Session["NomeCompleto"] = tb.Rows[0]["NomeCompleto"].ToString(); // Inicializa a classe de autenticação do usuário FormsAuthentication.Initialize(); //Define os dados do ticket de autenticação FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1, Session["NomeCompleto"].ToString(), DateTime.Now, DateTime.Now.AddMinutes(30), false, Session["NomeCompleto"].ToString(), FormsAuthentication.FormsCookiePath); // Grava o ticket no cookie de autenticação Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket))); // redirecionar para a home Response.Redirect("~/Default.aspx"); } else { Mensagem.Text = "Dados Invalidos."; } } }
protected void Excluir_Click(object sender, EventArgs e) { try { AppDatabase.OleDBTransaction db = new AppDatabase.OleDBTransaction(); db.ConnectionString = conexao; if (MotivoList.SelectedIndex == 0) { ErroMotivo.InnerText = "Informe o motivo"; } else if (MotivoList.SelectedIndex == 3 && Reagendou == true) { if (HoraAgendamento.Text.Trim() == "" || DataAgendamento.Text.Trim() == "") { ErroMotivo.InnerText = "Preencha todos os campos"; } else { string comando = "UPDATE Pedido SET Data_Agendamento='" + DataAgendamento.Text + "',Hora_Agendamento='" + HoraAgendamento.Text + "' WHERE Codigo=" + Codigo.Text; db.Query(comando); Erro.Text = "Coleta reagendada com sucesso"; RecuperarDados(); } } else { string comando = "INSERT INTO CotNaoAceitas(Motivo,Razao) VALUES('" + MotivoList.SelectedValue.ToString() + "','" + "Coleta nao realizada" + "');"; string commando = "DELETE * FROM Pedido WHERE Codigo=" + Codigo.Text; db.Query(comando); db.Query(commando); Erro.Text = "Coleta Removida com sucesso"; RecuperarDados(); } } catch (Exception ex) { RecoverExceptions re = new RecoverExceptions(); re.SaveException(ex); Erro.Text = "Houve uma falha inesperada"; } }
protected void Observacao_TextChanged(object sender, EventArgs e) { try { string comando = "UPDATE Pedido SET Observacao='" + Observacao.Text + "'WHERE Codigo=" + codigo.Text; AppDatabase.OleDBTransaction db = new AppDatabase.OleDBTransaction(); db.ConnectionString = conexao; db.Query(comando); Obs.Visible = true; ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alert", "HideLabel();", true); } catch (Exception ex) { RecoverExceptions re = new RecoverExceptions(); re.SaveException(ex); Obs.Text = "Houve uma falha inesperada"; } }
// MÉTODO QUE SELECIONA UM ITEM DO GRID PARA EDIÇÃO protected void ListaComputadores_SelectedIndexChanged(object sender, EventArgs e) { Codigo.Value = ListaComputadores.SelectedRow.Cells[1].Text; string sql = "SELECT * FROM Computadores WHERE Codigo=" + Codigo.Value; // faz a conexão e envia o comando SQL db = new ConexaoDB().GetConnection(); DataTable tb = (DataTable)db.Query(sql); if (tb.Rows.Count == 1) { Endereco.Text = tb.Rows[0]["Endereco"].ToString(); Nome.Text = tb.Rows[0]["Nome"].ToString(); Descricao.Text = tb.Rows[0]["Descricao"].ToString(); Excluir.Visible = true; } }
protected void Realizada_Click(object sender, EventArgs e) { try { TimeSpan ts = new TimeSpan(3, 0, 0); string comando = "UPDATE Pedido SET Status='Aguardando Nota',Atual_Status='" + DateTime.UtcNow.Subtract(ts).ToString() + "' WHERE Codigo=" + Codigo.Text; AppDatabase.OleDBTransaction db = new AppDatabase.OleDBTransaction(); db.ConnectionString = conexao; db.Query(comando); Erro.Text = "Transporte atualizado com sucesso"; RecuperarDados(); } catch (Exception ex) { Erro.Text = "Houve uma falha inesperada"; RecoverExceptions re = new RecoverExceptions(); re.SaveException(ex); } }
protected void Salvar_Click(object sender, EventArgs e) { string sql = ""; if (Codigo.Value == "") { sql = "INSERT INTO Computadores(Nome, Endereco, Descricao) VALUES('" + Nome.Text + "', '" + Endereco.Text + "','" + Descricao.Text + "');"; } else { sql = "UPDATE Computadores SET Nome = '" + Nome.Text + "', Endereco = '" + Endereco.Text + "', Descricao = '" + Descricao.Text + "' WHERE Codigo = " + Codigo.Value + ";"; } // CONECTA NO BANCO DE DADOS db = new ConexaoDB().GetConnection(); db.Query(sql); LimparControles(); }