Ejemplo n.º 1
0
 //////// CLIENTE
 ///
 public bool cadastrar_cliente(inicioDTO cli)
 {
     if (Conexao.con.State.ToString() == "Open")
     {
         Conexao.con.Close();
     }
     try
     {
         bool result = false;
         Conexao.con.Open();
         MySqlCommand cmd = Conexao.con.CreateCommand();
         cmd.CommandType = CommandType.Text;
         cmd.CommandText = "call cadastrar_cliente(@nome, @cpf, @email, @celular, @status, @sexo)";
         cmd.Parameters.AddWithValue("@nome", cli.nomeCliente);
         cmd.Parameters.AddWithValue("@cpf", cli.cpfCliente);
         cmd.Parameters.AddWithValue("@email", cli.emailCliente);
         cmd.Parameters.AddWithValue("@celular", cli.celularCliente);
         cmd.Parameters.AddWithValue("@sexo", cli.sexoCliente);
         cmd.Parameters.AddWithValue("@status", cli.regularizadoCliente);
         if (cmd.ExecuteNonQuery() > 0)
         {
             Conexao.con.Close();
             result = true;
         }
         return(result);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Não foi possível inserir o registro: " + ex.Message);
         Conexao.con.Close();
         return(false);
     }
 }
Ejemplo n.º 2
0
 public bool atualizar_status_emprestimo(inicioDTO cli)
 {
     if (Conexao.con.State.ToString() == "Open")
     {
         Conexao.con.Close();
     }
     try
     {
         bool result = false;
         Conexao.con.Open();
         MySqlCommand cmd = Conexao.con.CreateCommand();
         cmd.CommandType = CommandType.Text;
         cmd.CommandText = "call atualizar_emprestimo(@id, @dataEntrega, @status)";
         cmd.Parameters.AddWithValue("@id", cli.idEmprestimo);
         cmd.Parameters.AddWithValue("@dataEntrega", cli.dataEntrega);
         cmd.Parameters.AddWithValue("@status", cli.statusEmprestimo);
         if (cmd.ExecuteNonQuery() > 0)
         {
             Conexao.con.Close();
             result = true;
         }
         return(result);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Não foi possível alterar o registro: " + ex.Message);
         Conexao.con.Close();
         return(false);
     }
 }
 private void btExcluir_Click(object sender, EventArgs e)
 {
     if (dgvListaClientes.CurrentRow.Cells[0].Value != null)
     {
         DialogResult resp = MessageBox.Show("Deseja realmente excluir este registro?", "Excluir", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
         if (resp == System.Windows.Forms.DialogResult.Yes)
         {
             bool      result = false;
             inicioDTO idto   = new inicioDTO();
             inicioBLL ibll   = new inicioBLL();
             idto.idCliente = dgvListaClientes.CurrentRow.Cells[0].Value.ToString();
             result         = ibll.excluir_cliente(idto);
             if (result == true)
             {
                 MessageBox.Show("Registro excluido com sucesso!");
                 dgvListaClientes.Rows.Clear();
                 carregar_clientes();
             }
         }
     }
     else
     {
         MessageBox.Show("Escolha um registro para excluir.");
     }
 }
Ejemplo n.º 4
0
 //////// EMPRESTIMO
 ///
 public bool cadastrar_emprestimo(inicioDTO emp)
 {
     if (Conexao.con.State.ToString() == "Open")
     {
         Conexao.con.Close();
     }
     try
     {
         bool result = false;
         Conexao.con.Open();
         MySqlCommand cmd = Conexao.con.CreateCommand();
         cmd.CommandType = CommandType.Text;
         cmd.CommandText = "call cadastrar_emprestimo(@entrega, @idFuncionario, @idCliente, @idLivro, @valorEmprestimo)";
         cmd.Parameters.AddWithValue("@entrega", emp.dataPrevistaEntrega);
         cmd.Parameters.AddWithValue("@idFuncionario", emp.idFuncionarioEmprestimo);
         cmd.Parameters.AddWithValue("@idCliente", emp.idClienteEmprestimo);
         cmd.Parameters.AddWithValue("@idLivro", emp.idLivroEmprestimo);
         cmd.Parameters.AddWithValue("@valorEmprestimo", emp.totalEmprestimo);
         if (cmd.ExecuteNonQuery() > 0)
         {
             Conexao.con.Close();
             result = true;
         }
         return(result);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Não foi possível inserir o registro: " + ex.Message);
         Conexao.con.Close();
         return(false);
     }
 }
Ejemplo n.º 5
0
        private void btConfirmarCadastro_Click(object sender, EventArgs e)
        {
            bool         result = false;
            DialogResult resp   = MessageBox.Show("Deseja cadastrar este cliente?", "Confirmação", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);

            if (resp == System.Windows.Forms.DialogResult.Yes)
            {
                string csexo = cboSexoCliente.Text.Substring(0, 1).ToLower();

                inicioDTO idto = new inicioDTO();
                idto.nomeCliente    = txtNomeCliente.Text;
                idto.cpfCliente     = txtCpfCliente.Text;
                idto.emailCliente   = txtEmailCliente.Text;
                idto.celularCliente = txtCelularCliente.Text;
                if (cboClienteRegularizado.Text == "Regularizado")
                {
                    idto.regularizadoCliente = "regularizado";
                }
                else
                {
                    idto.regularizadoCliente = "nao_regularizado";
                }
                idto.sexoCliente = csexo;

                inicioBLL ibll = new inicioBLL();
                result = ibll.cadastrar_cliente(idto);
                if (result == true)
                {
                    MessageBox.Show("Cliente Cadastrado!", "Resultado", MessageBoxButtons.OK);
                }
                this.Close();
            }
        }
        private void btAtualizarCliente_Click(object sender, EventArgs e)
        {
            DialogResult resp = MessageBox.Show("Deseja atualizar este registro?", "Atualizar", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (resp == System.Windows.Forms.DialogResult.Yes)
            {
                bool      result = false;
                inicioDTO idto   = new inicioDTO();
                idto.idCliente      = txtIdCliente.Text;
                idto.nomeCliente    = txtNomeCliente.Text;
                idto.cpfCliente     = txtCpfCliente.Text;
                idto.emailCliente   = txtEmailCliente.Text;
                idto.celularCliente = txtCelularCliente.Text;
                if (cboStatusCliente.Text == "Regularizado")
                {
                    idto.regularizadoCliente = "regularizado";
                }
                else
                {
                    idto.regularizadoCliente = "nao_regularizado";
                }
                idto.sexoCliente = cboSexoCliente.Text.Substring(0, 1).ToLower();
                inicioBLL ibll = new inicioBLL();
                result = ibll.editar_cliente(idto);
                if (result == true)
                {
                    MessageBox.Show("Registro atualizado.");
                }
                else
                {
                    MessageBox.Show("Não foi possível atualizar o registro.");
                }
                this.Close();
            }
        }
        private void btConfirmarEmprestimo_Click(object sender, EventArgs e)
        {
            bool result = false;
            DialogResult resp = MessageBox.Show("Deseja cadastrar este emprestimo?", "Confirmação", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
            if (resp == System.Windows.Forms.DialogResult.Yes)
            {
                var dia = dtpEntregaPrevista.Value.Day.ToString("d");
                var mes = dtpEntregaPrevista.Value.Month.ToString();
                var ano = dtpEntregaPrevista.Value.Year.ToString();

                if (mes.Length == 1)
                {
                    mes = "0" + mes;
                }
                data = ano + "-" + mes + "-" + dia;
                hora = dtpHorarioDevolucao.Value.TimeOfDay.ToString();

                int pos = hora.LastIndexOf(".");
                if (pos != 0 && pos > 0)
                {
                    hora = hora.Substring(0, pos);
                }
                entregaPrevista = data + " " + hora;

                string idLivro;
                if (livros != null)
                {
                    idLivro = livros[cboLivroEmprestimo.SelectedIndex].Cells[0].Value.ToString();
                }
                else
                {
                    idLivro = codLivros[cboLivroEmprestimo.SelectedIndex].idLivro.ToString();
                }

                inicioDTO idto = new inicioDTO();
                idto.dataPrevistaEntrega = entregaPrevista;
                idto.idFuncionarioEmprestimo = usuarioSessaoDTO.idUsuario.ToString();
                idto.idClienteEmprestimo = listClientes[cboClienteEmprestimo.SelectedIndex].idCliente.ToString();
                idto.idLivroEmprestimo = idLivro;
                idto.totalEmprestimo = valorEmprestimo;

                inicioBLL ibll = new inicioBLL();
                result = ibll.cadastrar_emprestimo(idto); 
                if (result == true)
                {
                    MessageBox.Show("Emprestimo Cadastrado! \nEntrega prevista para: " + data + " às " + hora, "Resultado", MessageBoxButtons.OK);
                    this.Close();
                }
            }
        }
        private void carregar_emprestimos()
        {
            if (Conexao.con.State.ToString() == "Open")
            {
                Conexao.con.Close();
            }
            Conexao.con.Open();
            MySqlCommand cmd = Conexao.con.CreateCommand();

            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "call carregar_emprestimos";
            cmd.ExecuteNonQuery();

            Conexao.con.Close();
            DataTable        dt = new DataTable();
            MySqlDataAdapter da = new MySqlDataAdapter(cmd);

            da.Fill(dt);
            DateTime dateObj = DateTime.Now;
            var      hoje    = dateObj.Date;

            foreach (DataRow row in dt.Rows)
            {
                inicioBLL ibll = new inicioBLL();
                inicioDTO idto = new inicioDTO();

                DateTime dateObjMysql    = Convert.ToDateTime(row[2]);
                var      entregaPrevista = dateObjMysql.Date;
                var      status          = row[4];

                if (row[4].ToString() == "pontual" && DateTime.Compare(hoje, entregaPrevista) > 0)
                {
                    idto.statusEmprestimo = "atraso";
                    idto.idEmprestimo     = row[0].ToString();
                    idto.dataEntrega      = null;
                    ibll.atualizar_status_emprestimo(idto);
                    status = "atraso";
                }
                idto.idEmprestimo = row[0].ToString();
                string multa = ibll.pesquisar_multa_emprestimo(idto);
                dgvListaEmprestimos.Rows.Add(row[0], row[7], row[6], row[1], row[2], row[3], status, multa, row[5], row[8]);
            }
        }
 private void btSalvarEmprestimo_Click(object sender, EventArgs e)
 {
     if (cboStatusEmprestimo.SelectedIndex != i || ckbLivroEntregue.Checked == true)
     {
         DateTime  dt   = DateTime.Now;
         inicioDTO idto = new inicioDTO();
         idto.idEmprestimo     = txtIdEmprestimo.Text;
         idto.dataEntrega      = dt.ToString("yyyy-MM-dd HH:mm");
         idto.statusEmprestimo = cboStatusEmprestimo.Text;
         inicioBLL ibll = new inicioBLL();
         ibll.atualizar_status_emprestimo(idto);
         if (ckbMultaPaga.Checked == true)
         {
             ibll.atualizar_multa_paga(idto);
         }
     }
     else
     {
         MessageBox.Show("Para atualizar este registro deve haver alguma alteração.");
     }
     this.Close();
 }
Ejemplo n.º 10
0
        private void btConfirmarReserva_Click(object sender, EventArgs e)
        {
            inicioDTO idto = new inicioDTO();
            inicioBLL ibll = new inicioBLL();

            if (cboClienteReserva.Enabled == false && cboLivroReserva.Enabled == false)
            {
                //ATUALIZAR
                DialogResult resp = MessageBox.Show("Deseja atualizar esta reserva?", "Confirmação", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                if (resp == System.Windows.Forms.DialogResult.Yes)
                {
                    bool fechamento = false;
                    if (cboStatusReserva.Text == "Concluida")
                    {
                        fechamento = true;
                    }

                    var dia = dtpRetiradaPrevista.Value.Day.ToString("d");
                    var mes = dtpRetiradaPrevista.Value.Month.ToString();
                    var ano = dtpRetiradaPrevista.Value.Year.ToString();

                    if (mes.Length == 1)
                    {
                        mes = "0" + mes;
                    }

                    var data = ano + "-" + mes + "-" + dia;
                    var hora = dtpHoraRetiradaPrevista.Value.TimeOfDay.ToString();

                    int pos = hora.LastIndexOf(".");
                    if (pos != 0 && pos > 0)
                    {
                        hora = hora.Substring(0, pos);
                    }

                    var stringDataRetirada = data + " " + hora;

                    idto.idReserva            = reserva.idReserva;
                    idto.statusReserva        = cboStatusReserva.Text;
                    idto.dataRetiradaPrevista = stringDataRetirada;
                    if (ibll.editar_reserva(idto) == true)
                    {
                        MessageBox.Show("Reserva atualizada com sucesso!");
                        if (fechamento == true)
                        {
                            btConfirmarReserva.BackColor = Color.FromArgb(224, 224, 224);
                            btConfirmarReserva.ForeColor = Color.FromArgb(10, 10, 10);
                            btConfirmarReserva.Enabled   = false;
                            btRealizarEmprestimo.Visible = true;
                        }
                        else
                        {
                            this.Close();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Não foi possível atualizar a reserva.");
                    }
                }
            }
            else
            {
                // CADASTRAR
                DialogResult resp = MessageBox.Show("Deseja cadastrar esta reserva?", "Confirmação", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                if (resp == System.Windows.Forms.DialogResult.Yes)
                {
                    var dia = dtpRetiradaPrevista.Value.Day.ToString("d");
                    var mes = dtpRetiradaPrevista.Value.Month.ToString();
                    var ano = dtpRetiradaPrevista.Value.Year.ToString();

                    if (mes.Length == 1)
                    {
                        mes = "0" + mes;
                    }

                    var data = ano + "-" + mes + "-" + dia;
                    var hora = dtpHoraRetiradaPrevista.Value.TimeOfDay.ToString();

                    int pos = hora.LastIndexOf(".");
                    if (pos != 0 && pos > 0)
                    {
                        hora = hora.Substring(0, pos);
                    }

                    var stringDataRetirada = data + " " + hora;

                    if (cboClienteReserva.SelectedIndex < 0 && cboClienteReserva.Text != "")
                    {
                        cboClienteReserva.SelectedIndex = 0;
                    }

                    if (cboLivroReserva.SelectedIndex < 0 && cboLivroReserva.Text != "")
                    {
                        cboLivroReserva.SelectedIndex = 0;
                    }

                    idto.idCliente            = clientes[cboClienteReserva.SelectedIndex].idCliente;
                    idto.idLivro              = livros[cboLivroReserva.SelectedIndex].idLivro;
                    idto.idEmprestimo         = txtCodigoEmprestimo.Text;
                    idto.dataRetiradaPrevista = stringDataRetirada;
                    if (ibll.cadastrar_reserva(idto) == true)
                    {
                        MessageBox.Show("Reserva efetuada com sucesso!");
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Não foi possível realizar a reserva.");
                    }
                }
            }
        }