Пример #1
0
        private void btnAlterar_Click(object sender, EventArgs e)
        {
            if (lsvClientes.SelectedIndices.Count == 0)
            {
                MessageBox.Show("Selecione um cliente para ser alterado!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else if (lsvClientes.SelectedIndices.Count > 1)
            {
                MessageBox.Show("Selecione somente um cliente para ser alterado!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            using (var frmLogin = new FormLogin())
            {
                frmLogin.ShowDialog();
                if (!frmLogin.Logado)
                {
                    return;
                }
            }

            int idCliente = clientes[lsvClientes.SelectedIndices[0]].Id;

            using (var cliente = new Cliente())
            {
                using (var conn = new Connection())
                {
                    if (!cliente.SetById(idCliente, conn, null))
                    {
                        MessageBox.Show($"Não foi possível encontrar o cliente com id `{idCliente}`", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        CarregarClientes();
                        return;
                    }
                }

                using (var frmDadosPessoais = new FormDadosPessoaisCliente(cliente))
                {
                    frmDadosPessoais.btnAlterarPesquisa.Visible = true;

                    if (frmDadosPessoais.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    frmDadosPessoais.SetDadosInModel(cliente);
                }

                using (var conn = new Connection())
                {
                    cliente.Salvar(false, conn, null);
                    MessageBox.Show("Informações do cliente salva com sucesso!", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    CarregarClientes();
                }
            }
        }
Пример #2
0
 private void termoDeResponsabilidadeToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (var frmLogin = new FormLogin())
         using (var frmConfigurarTermoResponsabilidade = new FormConfigurarTermoResponsabilidade())
         {
             frmLogin.ShowDialog();
             if (frmLogin.Logado)
             {
                 frmConfigurarTermoResponsabilidade.ShowDialog();
             }
         }
 }
Пример #3
0
        private void importarClientesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var frmLogin = new FormLogin())
            {
                frmLogin.ShowDialog();
                if (!frmLogin.Logado)
                {
                    return;
                }
            }

            using (var frmImportacaoSelecionarArquivo = new frmImportacaoSelecionarArquivo())
            {
                frmImportacaoSelecionarArquivo.ShowDialog();
            }
        }
Пример #4
0
        private void usuáriosToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var frmLogin = new FormLogin())
            {
                frmLogin.ShowDialog();
                if (!frmLogin.Logado)
                {
                    return;
                }
            }

            using (var frmUsuarios = new frmUsuarios())
            {
                frmUsuarios.ShowDialog();
            }
        }
Пример #5
0
        private void tatuagensToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var frmLogin = new FormLogin())
            {
                frmLogin.ShowDialog();
                if (!frmLogin.Logado)
                {
                    return;
                }
            }

            using (var frmPerguntas = new FormPerguntas(TipoPergunta.Tatuagem))
            {
                frmPerguntas.ShowDialog();
            }
        }
Пример #6
0
        private void btnVisualizarPesquisa_Click(object sender, EventArgs e)
        {
            if (lsvClientes.SelectedIndices.Count != 1)
            {
                return;
            }

            using (var frmLogin = new FormLogin())
            {
                frmLogin.ShowDialog();
                if (!frmLogin.Logado)
                {
                    return;
                }
            }

            try
            {
                using (var frmPesquisa = new FormPesquisa(TipoPergunta.Cliente, PesquisaControl.TipoFonte.Normal, true, clientes[lsvClientes.SelectedIndices[0]].Id))
                {
                    if (frmPesquisa.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    using (var conn = new Connection())
                        using (var transaction = conn.BeginTransaction())
                        {
                            try
                            {
                                Resposta.SalvarRespostas(TipoPergunta.Cliente, clientes[lsvClientes.SelectedIndices[0]].Id, frmPesquisa.Respostas, conn, transaction);

                                transaction.Commit();
                            }
                            catch (Exception erro)
                            {
                                transaction.Rollback();
                                MessageBox.Show(erro.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                }
            } catch (PerguntasNotFoundException erro)
            {
                MessageBox.Show(erro.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #7
0
        private void btnRemover_Click(object sender, EventArgs e)
        {
            if (lsvClientes.SelectedIndices.Count == 0)
            {
                MessageBox.Show("Selecione um cliente para ser removido!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            // Verificando se o usuário deseja realmente remover os clientes selecionados
            if (MessageBox.Show($"Deseja realmente remover os {lsvClientes.SelectedIndices.Count} clientes selecionados?\nEssa ação não poderá ser revertida!", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }

            using (var frmLogin = new FormLogin())
            {
                frmLogin.ShowDialog();
                if (!frmLogin.Logado)
                {
                    return;
                }
            }

            using (var conn = new Connection())
                using (SQLiteTransaction transaction = conn.BeginTransaction())
                {
                    try
                    {
                        for (int i = 0; i < lsvClientes.SelectedIndices.Count; i++)
                        {
                            clientes[lsvClientes.SelectedIndices[i]].Remover(conn, transaction);
                        }

                        transaction.Commit();

                        MessageBox.Show($"{lsvClientes.SelectedIndices.Count} cliente(s) foi(ram) removido(s) com sucesso!", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        CarregarClientes();
                    }
                    catch (Exception erro)
                    {
                        transaction.Rollback();
                        MessageBox.Show($"Ocorreu um erro ao remover os clientes, a ação foi canacelada!\n{erro.Message}", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
        }