/// <summary> /// Evento lançado no clique do botão de remover o campo selecionado /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_removerCampo_Click(object sender, System.EventArgs e) { Util.CL_Files.WriteOnTheLog("UC_ControleTabelas().btn_removerCampo_Click()", Util.Global.TipoLog.DETALHADO); if (this.dgv_tabelas.SelectedRows.Count == 0) { Message.MensagemAlerta("Selecione alguma tabela"); } else if (this.dgv_campos.SelectedRows.Count == 0) { Message.MensagemAlerta("Selecione algum campo"); } else { int indexCampo = this.dgv_campos.SelectedRows[0].Index; Model.MD_Campos campo = this.listaCampos[indexCampo]; if (Message.MensagemConfirmaçãoYesNo("Deseja realmente excluir o campo " + campo.DAO.Nome + "?") == DialogResult.Yes) { if (campo.DAO.Delete()) { this.dgv_campos.Rows.RemoveAt(indexCampo); this.listaCampos.RemoveAt(indexCampo); Message.MensagemSucesso("Excluído com sucesso"); } } } }
/// <summary> /// Construtor principal da classe /// </summary> /// <param name="tarefa">Tarefa a ser efetuada pela tela</param> /// <param name="campo">Campo a ser visualizado/editado/excluído</param> /// <param name="principal">Tela principal para controle</param> public UC_CadastroCampos(Util.Enumerator.Tarefa tarefa, Model.MD_Campos campo, Model.MD_Tabela tabela, FO_Principal principal, UC_ControleTabelas controleTabelas) { Util.CL_Files.WriteOnTheLog("UC_CadastroCampos()", Util.Global.TipoLog.DETALHADO); this.tarefa = tarefa; this.campoCorrente = campo; this.tabela = tabela; this.principal = principal; this.controleTabelas = controleTabelas; this.InitializeComponent(); this.InicializaUserControl(); }
/// <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 AbrirCadastroRelacao(Model.MD_Campos campoOrigem, Tarefa tarefa, Model.MD_Relacao relacao = null) { Util.CL_Files.WriteOnTheLog("FO_Principal.AbrirCadastroRelacao()", Util.Global.TipoLog.DETALHADO); Visao.FO_Relacionamento cadastro = null; if (relacao == null) { cadastro = new Visao.FO_Relacionamento(tarefa, campoOrigem, this); } else { cadastro = new Visao.FO_Relacionamento(tarefa, new Model.MD_Campos(relacao.DAO.CampoOrigem.Codigo, relacao.DAO.CampoOrigem.Tabela.Codigo, relacao.DAO.Projeto.Codigo), this, relacao); } cadastro.ShowDialog(); }
/// <summary> /// Contrutor principal da classe /// </summary> /// <param name="tarefa">Tarefa a ser executada na tela</param> /// <param name="campoOrigem">Campo de origem do relacionamento</param> /// <param name="principal">tela principal para controle de eventos</param> public FO_Relacionamento(Util.Enumerator.Tarefa tarefa, Model.MD_Campos campoOrigem, FO_Principal principal, Model.MD_Relacao relacao = null) { Util.CL_Files.WriteOnTheLog("FO_Relacionamento()", Util.Global.TipoLog.DETALHADO); this.campoOrigem = campoOrigem; if (relacao != null) { this.campoDestino = new Model.MD_Campos(relacao.DAO.CampoDestino.Codigo, relacao.DAO.CampoDestino.Tabela.Codigo, relacao.DAO.CampoDestino.Projeto.Codigo); } this.relacao = relacao; this.principal = principal; this.tarefa = tarefa; this.InitializeComponent(); this.InicializaForm(); }
/// <summary> /// Evento lançado no clique da opção de visualizar campo /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_visualizarCampo_Click(object sender, System.EventArgs e) { Util.CL_Files.WriteOnTheLog("UC_ControleTabelas().btn_visualizarCampo_Click()", Util.Global.TipoLog.DETALHADO); if (this.dgv_tabelas.SelectedRows.Count == 0) { Message.MensagemAlerta("Selecione alguma tabela"); } else if (this.dgv_campos.SelectedRows.Count == 0) { Message.MensagemAlerta("Selecione algum campo"); } else { Model.MD_Tabela tabela = this.listaTabelas[this.dgv_tabelas.SelectedRows[0].Index]; Model.MD_Campos campo = this.listaCampos[this.dgv_campos.SelectedRows[0].Index]; this.principal.AbrirCadastroCampo(tabela, Util.Enumerator.Tarefa.VISUALIZAR, this, campo); } }
/// <summary> /// Evento Lançado no clique do botão de incluir o relacionamento /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_incluirRelacionamento_Click(object sender, System.EventArgs e) { Util.CL_Files.WriteOnTheLog("UC_ControleTabelas().btn_incluirRelacionamento_Click()", Util.Global.TipoLog.DETALHADO); if (this.dgv_tabelas.SelectedRows.Count == 0) { Message.MensagemAlerta("Selecione alguma tabela"); } else if (this.dgv_campos.SelectedRows.Count == 0) { Message.MensagemAlerta("Selecione algum campo"); } else { Model.MD_Campos campoOrigem = this.listaCampos[this.dgv_campos.SelectedRows[0].Index]; FO_Relacionamento relacionamento = new FO_Relacionamento(Util.Enumerator.Tarefa.INCLUIR, campoOrigem, principal); relacionamento.ShowDialog(); } }
/// <summary> /// Método que confirma o formulário /// </summary> private void Confirmar() { Util.CL_Files.WriteOnTheLog("FO_Relacionamento.Confirmar()", Util.Global.TipoLog.DETALHADO); if (this.tarefa == Util.Enumerator.Tarefa.VISUALIZAR) { this.tarefa = Util.Enumerator.Tarefa.EDITAR; this.InicializaForm(); } else { if (this.VerificaCampos()) { Model.MD_Tabela tabelaDestino = new Model.MD_Tabela(int.Parse(this.cmb_tabela.SelectedValue.ToString()), this.campoOrigem.DAO.Projeto.Codigo); this.campoDestino = new Model.MD_Campos(int.Parse(this.cmb_campos.SelectedValue.ToString()), tabelaDestino.DAO.Codigo, tabelaDestino.DAO.Projeto.Codigo); Model.MD_Relacao relacao = (this.tarefa == Util.Enumerator.Tarefa.EDITAR ? this.relacao : new Model.MD_Relacao(DataBase.Connection.GetIncrement("RELACAO"), this.campoOrigem.DAO.Projeto, this.campoOrigem.DAO.Tabela, tabelaDestino.DAO, this.campoOrigem.DAO, this.campoDestino.DAO)); this.relacao = relacao; this.PreencheRelacao(ref relacao); bool worked = false; if (this.tarefa == Util.Enumerator.Tarefa.EDITAR) { worked = relacao.DAO.Update(); } else { worked = relacao.DAO.Insert(); } if (worked) { Message.MensagemSucesso("Cadastro efetuado com sucesso!"); this.tarefa = Util.Enumerator.Tarefa.VISUALIZAR; this.principal.CarregaTreeViewAutomaticamente(); this.InicializaForm(); } else { Message.MensagemErro("Erro ao cadastrar!"); } } } }
/// <summary> /// Método que carrega os campos /// </summary> /// <param name="tabela"></param> public void CarregaCampos(Model.MD_Campos campo) { Util.CL_Files.WriteOnTheLog("UC_ControleTabelas().CarregaCampos()", Util.Global.TipoLog.DETALHADO); List <string> list = new List <string>(); list.Add(campo.DAO.Nome); //Nome list.Add(campo.DAO.Comentario); //Descrição list.Add(campo.DAO.PrimaryKey ? "PK" : ""); //Primary key list.Add(campo.DAO.NotNull ? "NOTNULL" : ""); //NotNull list.Add(campo.DAO.Default == null ? "" : campo.DAO.Default.ToString()); //Default list.Add(string.IsNullOrEmpty(campo.DAO.Check) ? "" : campo.DAO.Check); //Check list.Add(campo.DAO.Precisao.ToString("0.00")); //Precisão list.Add(campo.DAO.ForeingKey ? "FK" : ""); //Foreing Key list.Add(campo.DAO.Dominio); //Domínio list.Add(campo.DAO.Tamanho.ToString("0000")); //Tamanho list.Add(campo.DAO.Unique ? "UNIQUE" : ""); // Unique this.dgv_campos.Rows.Add(list.ToArray()); }
/// <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> /// Método que carrega o objeto com os dados do formulário /// </summary> /// <param name="campo"></param> private void CarregaDados(ref Model.MD_Campos campo) { Util.CL_Files.WriteOnTheLog("UC_CadastroCampos.CarregaDados()", Util.Global.TipoLog.DETALHADO); campo.DAO.Check = this.tbx_check.Text; campo.DAO.Default = this.tbx_default.Text; campo.DAO.Comentario = this.tbx_descrição.Text; campo.DAO.Dominio = this.tbx_dominio.Text; campo.DAO.Nome = this.tbx_nomeCampo.Text; campo.DAO.TipoCampo = new Model.MD_TipoCampo(int.Parse(cmb_datatype.SelectedValue.ToString())).DAO; if (!string.IsNullOrEmpty(this.tbx_tamanho.Text)) { campo.DAO.Tamanho = int.Parse(this.tbx_tamanho.Text); } if (!string.IsNullOrEmpty(this.tbx_precisao.Text)) { campo.DAO.Precisao = decimal.Parse(this.tbx_precisao.Text); } campo.DAO.NotNull = this.ckb_notNull.Checked; campo.DAO.PrimaryKey = this.ckb_primarykey.Checked; campo.DAO.Unique = this.ckb_unique.Checked; }
/// <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 adiciona o campo na lista e carrega em tela /// </summary> /// <param name="campo"></param> public void AdicionaCampo(Model.MD_Campos campo) { Util.CL_Files.WriteOnTheLog("UC_ControleTabelas().AdicionaCampo()", Util.Global.TipoLog.DETALHADO); this.listaCampos.Add(campo); this.CarregaCampos(campo); }
/// <summary> /// Método que faz a confirmação /// </summary> private void Confirmar() { Util.CL_Files.WriteOnTheLog("UC_CadastroCampos.Confirmar()", Util.Global.TipoLog.DETALHADO); if (this.tarefa == Util.Enumerator.Tarefa.VISUALIZAR) { this.tarefa = Util.Enumerator.Tarefa.EDITAR; this.InicializaUserControl(); } else { if (this.ValidaCampos()) { Model.MD_Campos campo = (this.tarefa == Util.Enumerator.Tarefa.EDITAR ? this.campoCorrente : new Model.MD_Campos(DataBase.Connection.GetIncrement("CAMPOS"), this.tabela.DAO.Codigo, this.tabela.DAO.Projeto.Codigo)); this.CarregaDados(ref campo); if (this.tarefa == Util.Enumerator.Tarefa.INCLUIR && Model.MD_Campos.ExisteCampoTabela(tabela.DAO.Nome, campo.DAO.Nome, tabela.DAO.Projeto.Codigo)) { Message.MensagemAlerta("O campo " + campo.DAO.Nome + " já exise na tabela " + tabela.DAO.Nome + "!"); return; } bool exec = this.tarefa == Util.Enumerator.Tarefa.EDITAR ? campo.DAO.Update() : campo.DAO.Insert(); if (exec) { Message.MensagemSucesso((this.tarefa == Util.Enumerator.Tarefa.INCLUIR ? "Incluído" : "Alterado") + " com sucesso!"); if (this.tarefa == Util.Enumerator.Tarefa.INCLUIR) { if (this.controleTabelas != null) { this.controleTabelas.AdicionaCampo(campo); } if (Message.MensagemConfirmaçãoYesNo("Deseja cadastrar outro campo para a tabela?") == DialogResult.Yes) { this.tarefa = Util.Enumerator.Tarefa.INCLUIR; this.InicializaUserControl(); this.principal.CarregaTreeViewAutomaticamente(); } else { this.tarefa = Util.Enumerator.Tarefa.VISUALIZAR; this.campoCorrente = campo; this.InicializaUserControl(); this.principal.CarregaTreeViewAutomaticamente(); } } else { this.tarefa = Util.Enumerator.Tarefa.VISUALIZAR; this.campoCorrente = campo; this.InicializaUserControl(); this.principal.CarregaTreeViewAutomaticamente(); } } else { Message.MensagemErro("Erro ao cadastrar!"); } } } }
/// <summary> /// Método que retorna o tipo de campo /// </summary> /// <param name="campo">CAmpo para resgatar o tipo</param> /// <returns>Tipo do campo</returns> private static Util.Enumerator.DataType RetornaTipoCampo(Model.MD_Campos campo) { Util.Enumerator.DataType tipo = campo.TipoNucleo(); return(tipo); }
/// <summary> /// Método que abre a janela de cadastro de campo /// </summary> /// <param name="campo">Classe de instância do campo</param> /// <param name="tarefa"></param> public void AbrirCadastroCampo(Model.MD_Tabela tabela, Tarefa tarefa, UC_ControleTabelas controleTabelas = null, Model.MD_Campos campo = null) { Util.CL_Files.WriteOnTheLog("FO_Principal.AbrirCadastroCampo()", Util.Global.TipoLog.DETALHADO); this.AbreJanela(new Visao.UC_CadastroCampos(tarefa, campo, tabela, this, controleTabelas), "Cadastro de Campos", Telas.CADASTRO_CAMPOS); }