/// <summary> /// Método que trata as tabelas de importação e coloca nas tabelas definitivas vinculando com o projeto /// </summary> /// <param name="projeto">Código do projeto a se vincular as tabelas</param> private static void TratarImportacao(int codigo, ref List <Model.Tabela> tabelas, ref List <Model.Campo> campos, ref List <Model.Relacionamento> relacionamentos) { Util.CL_Files.WriteOnTheLog("Importador.TratarImportacao()", Util.Global.TipoLog.DETALHADO); Model.MD_Projeto projeto = new Model.MD_Projeto(codigo); BarraDeCarregamento barraCarregamento = new BarraDeCarregamento(tabelas.Count(), "Importando Tabelas"); barraCarregamento.Show(); TratarTabelas(projeto, ref tabelas, ref barraCarregamento); barraCarregamento.Hide(); barraCarregamento.Dispose(); barraCarregamento = null; barraCarregamento = new BarraDeCarregamento(campos.Count(), "Importando Colunas"); barraCarregamento.Show(); TratarColunas(projeto, ref campos, ref barraCarregamento); barraCarregamento.Hide(); barraCarregamento.Dispose(); barraCarregamento = null; barraCarregamento = new BarraDeCarregamento(relacionamentos.Count(), "Importando Relacionamentos"); barraCarregamento.Show(); TratarRelacionamento(projeto, ref relacionamentos, ref barraCarregamento); projeto = null; barraCarregamento.Hide(); barraCarregamento.Dispose(); barraCarregamento = null; }
/// <summary> /// Método que faz a inclusão do projeto /// </summary> private void Incluir() { Util.CL_Files.WriteOnTheLog("UC_CadastroProjeto.Incluir()", Util.Global.TipoLog.DETALHADO); if (ValidaCampos()) { // Cria tabela e relacionamentos Model.MD_Projeto p = new Model.MD_Projeto(-1); // Instancia objeto Model.MD_Projeto proj = tarefa == Util.Enumerator.Tarefa.INCLUIR ? new Model.MD_Projeto(DataBase.Connection.GetIncrement(p.DAO.table.Table_Name)) : proj = this.projetoCorrente; this.InstanciaDados(ref proj); if (tarefa == Util.Enumerator.Tarefa.INCLUIR) { this.IncluiProjeto(proj); } else { this.AtualizaProjeto(proj); } this.projetoCorrente = proj; this.tarefa = Util.Enumerator.Tarefa.INCLUIR; this.InicializaUserControl(); } }
/// <summary> /// Método que abre a janela de cadastro de projeto /// </summary> public void AbrirJanelaDeCadastroProjeto(Util.Enumerator.Tarefa tarefa, int codigo = -1) { Util.CL_Files.WriteOnTheLog("FO_Principal.AbrirJanelaDeCadastroProjeto()", Util.Global.TipoLog.DETALHADO); Model.MD_Projeto proj = new Model.MD_Projeto(codigo); this.AbreJanela(new Visao.UC_CadastroProjeto(tarefa, proj, this), "Cadastro de Projeto", Telas.CADASTRO_ENTRADA); }
/// <summary> /// Método que abre a janela de gerenciamento de tabelas /// </summary> /// <param name="codigo"></param> public void AbrirJanelaGerenciamentoTabelas(int codigo) { Util.CL_Files.WriteOnTheLog("FO_Principal.AbrirJanelaGerenciamentoTabelas()", Util.Global.TipoLog.DETALHADO); Model.MD_Projeto proj = new Model.MD_Projeto(codigo); this.AbreJanela(new Visao.UC_ControleTabelas(this, new Model.MD_Projeto(codigo)), "Tabelas - Projeto: " + proj.DAO.Nome, Telas.CONTROLE_TABELAS); }
/// <summary> /// Construtor principal da classe /// </summary> /// <param name="projeto">Projeto</param> public UC_ControleTabelas(Visao.FO_Principal principal, Model.MD_Projeto projeto) { this.principal = principal; InitializeComponent(); this.projeto = projeto; this.InicializaForm(); }
/// <summary> /// Método que monta o meno do node /// </summary> /// <param name="node"></param> private void MontaMenuTabela(Model.MD_Projeto project, ref TreeNode node) { Util.CL_Files.WriteOnTheLog("FO_Principal.MontaMenuTabela()", Util.Global.TipoLog.DETALHADO); ContextMenu menu = new ContextMenu(); if (project.DAO.StatusProjeto == Status.ATIVO) { MenuItem item_buscarTabelasBanco = new MenuItem("Buscar tabelas de banco de dados", item_buscarTabelasBancoDados_selected_Click); item_buscarTabelasBanco.Tag = project.DAO.Codigo; MenuItem item_gerarDER = new MenuItem("Gerar DER", item_gerarDER_selected_Click); item_gerarDER.Tag = project.DAO.Codigo; MenuItem item_gerarScript = new MenuItem("Gerar Scripts", item_gerarScriptsProjeto_selected_Click); item_gerarScript.Tag = project.DAO.Codigo; menu.MenuItems.Add(item_buscarTabelasBanco); menu.MenuItems.Add(item_gerarDER); menu.MenuItems.Add(item_gerarScript); } else { MenuItem item_ativar = new MenuItem("Ativar", item_ativar_selected_Click); item_ativar.Tag = project.DAO.Codigo; menu.MenuItems.Add(item_ativar); } node.ContextMenu = menu; }
/// <summary> /// Método que confirma o formulário /// </summary> private void Confirmar() { Util.CL_Files.WriteOnTheLog("FO_CadastroProjeto.Confirmar()", Util.Global.TipoLog.DETALHADO); string mensagem = string.Empty; if (this.FormalurioValido(ref mensagem)) { Model.MD_Projeto temp = new Model.MD_Projeto(-1); this.principal.projeto = new Model.MD_Projeto(DataBase.Connection.GetIncrement(temp.DAO.table.Table_Name)); this.principal.projeto.DAO.Nome = this.tbx_nomeprojeto.Text; this.principal.projeto.DAO.Descricao = this.tbx_descricaoProjeto.Text; temp = null; if (this.principal.projeto.DAO.Insert()) { Visao.Message.MensagemSucesso("Cadastrado o novo projeto"); this.DialogResult = DialogResult.OK; this.Dispose(); } else { Visao.Message.MensagemErro("Erro! Verificar Log!"); } } else { Visao.Message.MensagemAlerta(mensagem); } }
/// <summary> /// Método que abre a janela de cadastro de relação /// </summary> /// <param name="campo">Classe de instância do campo</param> /// <param name="tarefa"></param> public void AbrirDerNaAplicacao(Model.MD_Projeto projetoCorrente) { Util.CL_Files.WriteOnTheLog("FO_Principal.AbrirDerNaAplicacao()", Util.Global.TipoLog.DETALHADO); Visao.UC_WEB web = new Visao.UC_WEB(Util.Global.app_DER_file_Table); this.AbreJanela(web, "DER - " + projetoCorrente.DAO.Nome, Util.Enumerator.Telas.CADASTRO_RELATORIO); }
/// <summary> /// Construtor principal da classe /// </summary> /// <param name="projeto">Projeto para pegar as tabelas</param> public FO_GerarScripts(Model.MD_Projeto projeto, Model.MD_Tabela tabela) { this.projeto = projeto; this.tabela = tabela; InitializeComponent(); ckb_gerarArquivo.Checked = true; ckb_gerarArquivo.Visible = this.btn_info_gerarArquivo.Visible = false; }
/// <summary> /// Método que instancia os dados do projeto /// </summary> /// <param name="proj">Objeto a receber os dados</param> private void InstanciaDados(ref Model.MD_Projeto proj) { Util.CL_Files.WriteOnTheLog("UC_CadastroProjeto.InstanciaDados()", Util.Global.TipoLog.DETALHADO); proj.DAO.Nome = this.tbx_nomeProjeto.Text; proj.DAO.Descricao = this.tbx_descricao.Text; proj.DAO.Git = this.tbx_repositorio.Text; }
/// <summary> /// Evento lançado na seleção do botão direito no tree view /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void item_gerarClasses_selected_Click(object sender, EventArgs e) { Util.CL_Files.WriteOnTheLog("FO_Principal.item_gerarClasses_selected_Click()", Util.Global.TipoLog.DETALHADO); MenuItem item = (MenuItem)sender; string codigo = item.Tag.ToString(); Model.MD_Projeto projeto = new Model.MD_Projeto(int.Parse(codigo)); this.GerarClasses(projeto); }
/// <summary> /// Evento lançado na seleção do botão direito no tree view /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void item_incluirTabela_selected_Click(object sender, EventArgs e) { Util.CL_Files.WriteOnTheLog("FO_Principal.item_incluirTabela_selected_Click()", Util.Global.TipoLog.DETALHADO); MenuItem item = (MenuItem)sender; string codigo = item.Tag.ToString(); Model.MD_Projeto project = new Model.MD_Projeto(int.Parse(codigo)); this.AbrirCadastroTabela(project, Tarefa.INCLUIR); }
/// <summary> /// Construtor principal da classe /// </summary> /// <param name="tarefa">Qual a tarefa a ser executada na tela</param> public UC_CadastroProjeto(Util.Enumerator.Tarefa tarefa, Model.MD_Projeto projeto, FO_Principal principal) { Util.CL_Files.WriteOnTheLog("UC_CadastroProjeto()", Util.Global.TipoLog.DETALHADO); this.tarefa = tarefa; this.projetoCorrente = projeto; this.principal = principal; this.InitializeComponent(); this.InicializaUserControl(); }
/// <summary> /// Evento lançado na seleção do botão direito no tree view /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void item_desativar_selected_Click(object sender, EventArgs e) { Util.CL_Files.WriteOnTheLog("FO_Principal.item_desativar_selected_Click()", Util.Global.TipoLog.DETALHADO); MenuItem item = (MenuItem)sender; string codigo = item.Tag.ToString(); Model.MD_Projeto projeto = new Model.MD_Projeto(int.Parse(codigo)); projeto.DAO.StatusProjeto = Status.DESATIVADO; projeto.DAO.Update(); this.CarregaTreeViewAutomaticamente(); }
/// <summary> /// Construtor principal da classe /// </summary> /// <param name="tarefa">tarefa a ser realizada na tela</param> /// <param name="tabela">Instancia da classe de tabela</param> /// <param name="principal">Tela principal para controle do visual</param> public UC_CadastroTabela(Util.Enumerator.Tarefa tarefa, Model.MD_Tabela tabela, Model.MD_Projeto projeto, FO_Principal principal, UC_ControleTabelas controleTabelas = null) { Util.CL_Files.WriteOnTheLog("UC_CadastroTabela()", Util.Global.TipoLog.DETALHADO); this.InitializeComponent(); this.projeto = projeto; this.controleTabelas = controleTabelas; this.tabelaCorrente = new Model.MD_Tabela(tabela.DAO.Codigo, projeto.DAO.Codigo); this.principal = principal; this.tarefa = tarefa; this.gpb_cadastroGeral.Text = "Cadastro de tabela - Projeto " + this.projeto.DAO.Nome; this.InicializaUserControl(); }
/// <summary> /// Método que faz a inserção do projeto /// </summary> /// <param name="proj">Projeto a ser inserido</param> private void AtualizaProjeto(Model.MD_Projeto proj) { Util.CL_Files.WriteOnTheLog("UC_CadastroProjeto.AtualizaProjeto()", Util.Global.TipoLog.DETALHADO); if (proj.DAO.Update()) { Message.MensagemSucesso("Alterado com sucesso!"); this.AtualizaPrincipal(); } else { Message.MensagemErro("Erro ao alterar!"); } }
/// <summary> /// Método que gera as classes de um projeto /// </summary> /// <param name="projeto"></param> public void GerarClasses(Model.MD_Projeto projeto) { Util.CL_Files.WriteOnTheLog("FO_Principal.GerarClasses()", Util.Global.TipoLog.DETALHADO); string mensagemErro = string.Empty; List <Model.MD_Tabela> tabelas = projeto.GetTabelasProjeto(); List <Model.MD_Tabela> tabelas_erro = projeto.GetTabelasProjeto(); bool houveErro = false; if (tabelas.Count < 1) { Message.MensagemAlerta("Não há tabelas cadastradas para o projeto selecionado!"); } else { BarraDeCarregamento barra = new BarraDeCarregamento(tabelas.Count * 2, "Gerando as classes"); barra.Show(); foreach (Model.MD_Tabela t in tabelas) { barra.AvancaBarra(1); if (!this.GerarClasse(t, ref mensagemErro)) { tabelas_erro.Add(t); houveErro = true; } } barra.Close(); barra.Dispose(); barra = null; if (houveErro) { string retorno = "Houve erro nas tabelas:" + Environment.NewLine; foreach (Model.MD_Tabela t in tabelas_erro) { retorno += t.DAO.Nome + Environment.NewLine; } Message.MensagemAlerta(retorno); } else { Message.MensagemSucesso("As classes foram geradas no diretórios: " + Util.Global.app_classesSaida_directory + "!"); } } }
/// <summary> /// Método que faz a inserção do projeto /// </summary> /// <param name="proj">Projeto a ser inserido</param> private void IncluiProjeto(Model.MD_Projeto proj) { Util.CL_Files.WriteOnTheLog("UC_CadastroProjeto.IncluiProjeto()", Util.Global.TipoLog.DETALHADO); if (proj.DAO.Insert()) { Message.MensagemSucesso("Incluído com sucesso!"); this.tbx_descricao.Text = this.tbx_nomeProjeto.Text = string.Empty; this.AtualizaPrincipal(); } else { Message.MensagemErro("Erro ao inserir!"); } }
/// <summary> /// Método que trata as tabelas /// </summary> /// <param name="projeto">Projeto ao qual a tabela pertence</param> /// <param name="tabelas">Tabelas a serem importadas para o projeto</param> private static void TratarColunas(Model.MD_Projeto projeto, ref List <Model.Campo> campos, ref BarraDeCarregamento barra) { Util.CL_Files.WriteOnTheLog("Importador.TratarColunas()", Util.Global.TipoLog.DETALHADO); foreach (Model.Campo c in campos) { barra.AvancaBarra(1); bool existe = false; int campoCodigo = CodigoColuna(c, projeto.DAO.Codigo, ref existe); Model.Tabela t = new Model.Tabela(); t.nome = c.Tabela; bool x = true; Model.MD_Tabela tabela = new Model.MD_Tabela(CodigoTabela(t, projeto.DAO.Codigo, ref x), projeto.DAO.Codigo); Model.MD_Campos campo = new Model.MD_Campos(campoCodigo, tabela.DAO.Codigo, tabela.DAO.Projeto.Codigo); campo.DAO.Nome = c.Name_Field; campo.DAO.Default = c.ValueDefault; campo.DAO.NotNull = c.NotNull; campo.DAO.Precisao = c.Precision; campo.DAO.PrimaryKey = c.PrimaryKey; campo.DAO.Projeto = projeto.DAO; campo.DAO.Tamanho = c.Size; campo.DAO.TipoCampo = Model.MD_TipoCampo.RetornaTipoCampo(c.Type).DAO; campo.DAO.Unique = c.Unique; campo.DAO.Comentario = c.Comments; if (existe) { campo.DAO.Update(); } else { campo.DAO.Insert(); } campo = null; tabela = null; } }
/// <summary> /// Evento lançado na seleção do botão direito no tree view /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void item_excluirProjeto_selected_Click(object sender, EventArgs e) { Util.CL_Files.WriteOnTheLog("FO_Principal.item_excluirProjeto_selected_Click()", Util.Global.TipoLog.DETALHADO); MenuItem item = (MenuItem)sender; string codigo = item.Tag.ToString(); Model.MD_Projeto project = new Model.MD_Projeto(int.Parse(codigo)); if (Visao.Message.MensagemConfirmaçãoYesNo("Deseja excluir o projeto: " + project.DAO.Nome + "?") == DialogResult.Yes) { if (project.DAO.Delete()) { Visao.Message.MensagemSucesso("Excluído com sucesso!"); } else { Visao.Message.MensagemErro("Erro ao excluir!"); } this.CarregaTreeViewAutomaticamente(); this.FecharTela(Telas.CADASTRO_ENTRADA); } }
/// <summary> /// Método que gera o relatório do projeto selecionado /// </summary> public void GerarDer(Model.MD_Projeto projetoCorrente) { Util.CL_Files.WriteOnTheLog("FO_Principal.GerarDocumentoDER()", Util.Global.TipoLog.DETALHADO); if (Regras.DerCreator.Gerar(projetoCorrente)) { Message.MensagemSucesso("Gerado com sucesso!"); if (Message.MensagemConfirmaçãoYesNo("Deseja abrir o DER no Navegador?") == DialogResult.Yes) { System.Diagnostics.Process.Start(Util.Global.app_DER_file_Table); } else { Visao.UC_WEB web = new Visao.UC_WEB(Util.Global.app_DER_file_Table); this.AbreJanela(web, "DER - " + projetoCorrente.DAO.Nome, Util.Enumerator.Telas.CADASTRO_RELATORIO); } } else { Message.MensagemErro("Houve erro ao gerar o relatório!"); } }
/// <summary> /// Método que trata as tabelas /// </summary> /// <param name="projeto">Projeto ao qual a tabela pertence</param> /// <param name="tabelas">Tabelas a serem importadas para o projeto</param> private static void TratarTabelas(Model.MD_Projeto projeto, ref List <Model.Tabela> tabelas, ref BarraDeCarregamento barra) { Util.CL_Files.WriteOnTheLog("Importador.TratarTabelas()", Util.Global.TipoLog.DETALHADO); foreach (Model.Tabela t in tabelas) { barra.AvancaBarra(1); bool existe = false; int tableCodigo = CodigoTabela(t, projeto.DAO.Codigo, ref existe); Model.MD_Tabela tabela = new Model.MD_Tabela(tableCodigo, projeto.DAO.Codigo); tabela.DAO.Nome = t.nome; if (existe) { tabela.DAO.Update(); } else { tabela.DAO.Insert(); } tabela = null; } }
/// <summary> /// Método que carrega os projetos cadastrados e os coloca no treeView /// </summary> private TreeNode CarregaProjetos(ref BarraDeCarregamento aguarde) { Util.CL_Files.WriteOnTheLog("FO_Principal.CarregaProjetos()", Util.Global.TipoLog.DETALHADO); DbDataReader reader = DataBase.Connection.Select(new DAO.MD_Projeto().table.CreateCommandSQLTable()); TreeNode projetos = new TreeNode("Projetos"); while (reader.Read()) { aguarde.AvancaBarra(1); Model.MD_Projeto project = new Model.MD_Projeto(int.Parse(reader["CODIGO"].ToString())); TreeNode node = new TreeNode(project.DAO.Nome); node.Tag = "projetos:" + project.DAO.Codigo; node.ImageIndex = 0; node.SelectedImageIndex = 0; this.MontaMenuProjeto(project, ref node); if (project.DAO.StatusProjeto == Status.ATIVO) { TreeNode tabela = new TreeNode("Tabelas"); tabela.Tag = "tabelas:" + project.DAO.Codigo;; this.MontaMenuTabela(project, ref tabela); node.Nodes.Add(tabela); } projetos.Nodes.Add(node); } projetos.Tag = -1; projetos.Expand(); reader.Close(); return(projetos); }
/// <summary> /// Método que trata os relacionamentos /// </summary> /// <param name="projeto">Projeto ao qual o relacionamento pertence</param> /// <param name="relacionamentos">Relacionamentos a serem importadas para o projeto</param> private static void TratarRelacionamento(Model.MD_Projeto projeto, ref List <Model.Relacionamento> relacionamentos, ref BarraDeCarregamento barra) { Util.CL_Files.WriteOnTheLog("Importador.TratarRelacionamento()", Util.Global.TipoLog.DETALHADO); foreach (Model.Relacionamento r in relacionamentos) { barra.AvancaBarra(1); bool existe = false; int rCodigo = CodigoRelacionamento(r, projeto.DAO.Codigo, ref existe); Model.Tabela tabelaOrigemDesc = new Model.Tabela(); tabelaOrigemDesc.nome = r.tabelaOrigem; Model.Tabela tabelaDestinoDesc = new Model.Tabela(); tabelaDestinoDesc.nome = r.tabelaDestino; Model.Campo campoOrigemDesc = new Model.Campo(); campoOrigemDesc.Name_Field = r.campoOrigem; campoOrigemDesc.Tabela = tabelaOrigemDesc.nome; Model.Campo campoDestinoDesc = new Model.Campo(); campoDestinoDesc.Name_Field = r.campoDestino; campoDestinoDesc.Tabela = tabelaDestinoDesc.nome; bool x = true; Model.MD_Tabela tabelaOrigem = new Model.MD_Tabela(CodigoTabela(tabelaOrigemDesc, projeto.DAO.Codigo, ref x), projeto.DAO.Codigo); if (!x) { tabelaOrigem.DAO.Insert(); } Model.MD_Tabela tabelaDestino = new Model.MD_Tabela(CodigoTabela(tabelaDestinoDesc, projeto.DAO.Codigo, ref x), projeto.DAO.Codigo); if (!x) { tabelaDestino.DAO.Insert(); } Model.MD_Campos campoOrigem = new Model.MD_Campos(CodigoColuna(campoOrigemDesc, projeto.DAO.Codigo, ref x), tabelaOrigem.DAO.Codigo, tabelaOrigem.DAO.Projeto.Codigo); if (!x) { campoOrigem.DAO.Insert(); } Model.MD_Campos campoDestino = new Model.MD_Campos(CodigoColuna(campoDestinoDesc, projeto.DAO.Codigo, ref x), tabelaDestino.DAO.Codigo, tabelaDestino.DAO.Projeto.Codigo); if (!x) { campoDestino.DAO.Insert(); } Model.MD_Relacao relacao = new Model.MD_Relacao(rCodigo, projeto.DAO, tabelaOrigem.DAO, tabelaDestino.DAO, campoOrigem.DAO, campoDestino.DAO); relacao.DAO.NomeForeingKey = r.constraintName; if (existe) { relacao.DAO.Update(); } else { relacao.DAO.Insert(); } tabelaOrigemDesc = null; tabelaDestinoDesc = null; campoOrigemDesc = null; campoDestinoDesc = null; relacao = null; tabelaOrigem = null; tabelaDestino = null; campoOrigem = null; campoDestino = null; } }
/// <summary> /// Método que abre janela de cadastro de tabela /// </summary> /// <param name="project"></param> public void AbrirCadastroTabela(Model.MD_Projeto project, Tarefa tarefa, Visao.UC_ControleTabelas controletabelas = null, Model.MD_Tabela table = null) { Util.CL_Files.WriteOnTheLog("FO_Principal.AbrirCadastroTabela()", Util.Global.TipoLog.DETALHADO); this.AbreJanela(new Visao.UC_CadastroTabela(tarefa, table == null ? new Model.MD_Tabela(-1, project.DAO.Codigo) : table, project, this, controletabelas), "Cadastro de Tabela", Telas.CADASTRO_TABELAS); }
/// <summary> /// Método que gera os scripts de banco /// </summary> /// <param name="projeto">Projeto para capturar as tabelas</param> public void GerarScriptBD(Model.MD_Projeto projeto, Model.MD_Tabela tabela) { FO_GerarScripts form = new FO_GerarScripts(projeto, tabela); form.Show(); }
/// <summary> /// Método que gera os scripts de banco /// </summary> /// <param name="projeto">Projeto para capturar as tabelas</param> public void GerarScriptBD(Model.MD_Projeto projeto) { FO_GerarScripts form = new FO_GerarScripts(projeto); form.Show(); }
/// <summary> /// Método principal para fazer a criação do script /// </summary> /// <param name="projeto">Projeto para capturar as tabelas</param> /// <param name="banco">Tipo de banco</param> /// <param name="apenasUmArquivo"></param> /// <param name="caminho"></param> /// <returns></returns> public static bool CriarScript(Model.MD_Projeto projeto, Util.Enumerator.BancoDados banco, bool apenasUmArquivo, string caminho = null) { List <Model.MD_Tabela> table = projeto.GetTabelasProjeto(); return(CriarScript(table, banco, apenasUmArquivo, caminho)); }
/// <summary> /// Construtor principal da classe /// </summary> /// <param name="projeto">Projeto para pegar as tabelas</param> public FO_GerarScripts(Model.MD_Projeto projeto) { this.projeto = projeto; InitializeComponent(); }