Beispiel #1
0
        /// <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;
        }
Beispiel #2
0
        /// <summary>
        /// Método que abre o arquivo DER, lê e identifica todas as tabelas e suas colunas
        /// </summary>
        /// <param name="diretorioFile"></param>
        /// <returns></returns>
        public static List <MDN_Table> MontaTabela(string diretorioFile)
        {
            Util.CL_Files.WriteOnTheLog("Backup.MontaTabela()", Util.Global.TipoLog.DETALHADO);

            List <MDN_Table> tabelas = new List <MDN_Table>();

            List <string> linhas = TextoArquivo(diretorioFile);

            BarraDeCarregamento barraDeCarregamento = new BarraDeCarregamento(linhas.Count, "Importando DER");

            barraDeCarregamento.Show();

            string nome_tabela = string.Empty;
            string tipo_coluna = string.Empty;
            string tabela      = string.Empty;
            bool   inTable     = false;

            foreach (string linha in linhas)
            {
                barraDeCarregamento.AvancaBarra(1);

                if (linha.Contains("caption1"))
                {
                    nome_tabela = linha.Replace("<div class=\"caption1\">", "").Replace("</div>", "");
                }
                else if (linha.Contains("caption2"))
                {
                    tipo_coluna = linha.Replace("<div class=\"caption2\">", "").Replace("</div>", "");
                }
                else if (linha.Contains("table class=\"tabformat\""))
                {
                    inTable = true;
                }
                else if (inTable && tipo_coluna.ToUpper().Equals("COLUMNS"))
                {
                    if (linha.Contains("</table>"))
                    {
                        tabelas.Add(MontaConfiguracaoTabela(nome_tabela, tabela, barraDeCarregamento));
                        tabela      = string.Empty;
                        inTable     = false;
                        tipo_coluna = string.Empty;
                    }
                    else if (!string.IsNullOrEmpty(linha.Trim()))
                    {
                        tabela += linha;
                    }
                }
            }

            barraDeCarregamento.Dispose();
            barraDeCarregamento = null;

            linhas.Clear();
            linhas = null;

            return(tabelas);
        }
Beispiel #3
0
        /// <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;
            }
        }
Beispiel #4
0
        /// <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;
            }
        }
Beispiel #5
0
        /// <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;
            }
        }
Beispiel #6
0
        /// <summary>
        /// Método que preenche o corpo do html
        /// </summary>
        /// <param name="projeto">Projeto para se preencher o corpo do html</param>
        /// <param name="builder_tableB">string builder para montar o html</param>
        private static void PreencheText(Model.MD_Projeto projeto, ref StringBuilder builder_tableB, ref StringBuilder builder_tableR)
        {
            Util.CL_Files.WriteOnTheLog("Document.PreencheText", Global.TipoLog.SIMPLES);
            int quantidade = 0;

            string sentenca = "SELECT COUNT(1) AS contador FROM " + ClassesGenericas.tabelaBase.DAO.table.Table_Name + " WHERE PROJETO = " + projeto.DAO.Codigo;

            DbDataReader reader = DataBase.Connection.Select(sentenca);

            if (reader == null)
            {
                return;
            }

            while (reader.Read())
            {
                quantidade = int.Parse(reader["contador"].ToString());
            }

            sentenca = ClassesGenericas.tabelaBase.DAO.table.CreateCommandSQLTable() + " WHERE PROJETO = " + projeto.DAO.Codigo + " ORDER BY NOME";

            reader = DataBase.Connection.Select(sentenca);

            if (reader == null)
            {
                return;
            }

            BarraDeCarregamento barraCarregamento = new BarraDeCarregamento(quantidade, "Criando DER");

            barraCarregamento.Show();

            builder_tableR.Append("<div class=\"bookmark\">" + Environment.NewLine);

            while (reader.Read())
            {
                barraCarregamento.AvancaBarra(1);

                Model.MD_Tabela tabela = new MD_Tabela(int.Parse(reader["CODIGO"].ToString()), projeto.DAO.Codigo);

                builder_tableB.Append("<a name = \"Table_" + tabela.DAO.Codigo + "\"></a>" + Environment.NewLine);
                builder_tableB.Append("<div class=\"caption1\">" + tabela.DAO.Nome + "</div>" + Environment.NewLine);

                builder_tableB.Append("<div class=\"caption2\">Columns</div>" + Environment.NewLine);
                PreencheColunas(tabela, ref builder_tableB);

                builder_tableB.Append("<div class=\"caption2\">Relationships</div>" + Environment.NewLine);
                PreencheRelationships(tabela, ref builder_tableB);

                builder_tableB.Append("<div class=\"caption2\">Notes</div>" + Environment.NewLine);
                PreencheNotes(tabela, ref builder_tableB);

                builder_tableB.Append("<br><br> " + Environment.NewLine);

                builder_tableR.Append("<a href=\"TableB.html#Table_" + tabela.DAO.Codigo + "\"target=\"body\">" + tabela.DAO.Nome + "</a>" + Environment.NewLine);

                tabela = null;
            }
            builder_tableR.Append("</div>" + Environment.NewLine);

            barraCarregamento.Hide();
            barraCarregamento.Dispose();
            barraCarregamento = null;

            reader.Close();
        }
Beispiel #7
0
        /// <summary>
        /// Método que faz o tratamento da imagem
        /// </summary>
        public void TrataImagens()
        {
            string men = "";

            if (!ValidaPath(string.IsNullOrEmpty(tbx_folder.Text) ? tbx_file_in.Text : tbx_folder.Text, out men))
            {
                MessageBox.Show(men, "Atenção");
                return;
            }

            List <FileInfo> files = new List <FileInfo>();

            if (!string.IsNullOrEmpty(tbx_folder.Text))
            {
                DirectoryInfo directory = new DirectoryInfo(tbx_folder.Text);
                files = directory.GetFiles().ToList();
            }
            if (!string.IsNullOrEmpty(tbx_file_in.Text))
            {
                files.Add(new FileInfo(tbx_file_in.Text));
            }

            string mensagemErro = "";

            this.Hide();
            int total = 0;

            foreach (FileInfo arq in files)
            {
                if (arq.Extension == ".jpg" || arq.Extension == ".JPG" ||
                    arq.Extension == ".png" || arq.Extension == ".PNG" ||
                    arq.Extension == ".jpeg" || arq.Extension == ".JPEG" ||
                    arq.Extension == ".ico" || arq.Extension == ".ICO")
                {
                    total++;
                }
            }

            BarraDeCarregamento tela = new BarraDeCarregamento(total);

            tela.Show();

            sucesso = erro = 0;
            foreach (FileInfo arq in files)
            {
                if (arq.Extension == ".jpg" || arq.Extension == ".JPG" ||
                    arq.Extension == ".png" || arq.Extension == ".PNG" ||
                    arq.Extension == ".jpeg" || arq.Extension == ".JPEG" ||
                    arq.Extension == ".ico" || arq.Extension == ".ICO")
                {
                    tela.AvancaBarra(1);

                    if (TrataImagem(arq,
                                    int.Parse(tbx_width.Text),
                                    int.Parse(tbx_height.Text),
                                    ckb_transparent.Checked,
                                    ref mensagemErro))
                    {
                        sucesso++;
                    }
                    else
                    {
                        erro++;
                        lista_errados.Add(arq.FullName);
                        lista_errados_motivo.Add(mensagemErro);
                    }
                }
            }

            tela.Close();
            tela.Dispose();
            total = 0;
            this.Show();
            string mensagem = "Total: " + (sucesso + erro).ToString() + "\n\n";

            mensagem += "Imagens Tratadas: " + sucesso + "\n\n";

            foreach (string mens in lista_errados)
            {
                mensagem += "Imagens com erro: " + mens;
            }

            MessageBox.Show(mensagem);
        }
Beispiel #8
0
        /// <summary>
        /// Método que cria a coluna
        /// </summary>
        /// <param name="colunas">Colunas</param>
        /// <returns>Modelo de coluna</returns>
        private static MDN_Campo MontaColuna(List <string> colunas, BarraDeCarregamento barra)
        {
            Util.CL_Files.WriteOnTheLog("Backup.MontaColuna()", Util.Global.TipoLog.DETALHADO);

            MDN_Campo Campo = null;

            bool   primarykey = false;
            bool   notnull    = false;
            bool   unique     = false;
            object obj        = null;
            string colunaNome = "";

            Util.Enumerator.DataType type = Enumerator.DataType.INT;
            int size      = 0;
            int precision = 0;

            int i = 0;

            foreach (string coluna in colunas)
            {
                barra.AvancaBarra(1);
                if (string.IsNullOrEmpty(coluna))
                {
                    continue;
                }

                coluna.Replace("|", "");

                string palavra = coluna.Trim();

                switch (i)
                {
                case 0:     //Key
                    primarykey = palavra.ToUpper().Equals("PK");
                    break;

                case 1:     //Column name
                    colunaNome = palavra;
                    break;

                case 2:     //Domain
                    break;

                case 3:     // Data type
                    if (palavra.ToUpper().Contains("VARCHAR"))
                    {
                        type = Enumerator.DataType.STRING;
                        size = int.Parse(palavra.Split('(')[1].Replace(")", "").ToString());
                    }
                    else if (palavra.ToUpper().Contains("TIMESTAMP"))
                    {
                        type = Enumerator.DataType.DATE;
                    }
                    else if (palavra.ToUpper().Contains("DECIMAL"))
                    {
                        type      = Enumerator.DataType.DECIMAL;
                        size      = int.Parse(palavra.Split('(')[1].ToString().Split(',')[0].ToString());
                        precision = int.Parse(palavra.Split('(')[1].ToString().Split(',')[1].Replace(")", "").ToString());
                    }
                    else if (palavra.ToUpper().Contains("CHAR"))
                    {
                        type = Enumerator.DataType.CHAR;
                        size = int.Parse(palavra.Split('(')[1].Replace(")", "").ToString());
                    }
                    else if (palavra.ToUpper().Contains("INTEGER"))
                    {
                        type = Enumerator.DataType.INT;
                    }
                    break;

                case 4:     // Not Null
                    if (palavra.ToUpper().Equals("YES"))
                    {
                        notnull = true;
                    }
                    break;

                case 5:     // Unique
                    if (palavra.ToUpper().Equals("YES"))
                    {
                        unique = true;
                    }
                    break;

                case 6:     // Check
                    break;

                case 7:     // Default
                    obj = palavra.Replace("'", "").ToString();
                    break;

                case 8:     // Comments
                    break;

                case 9:     // Notes
                    break;
                }

                i++;
            }

            Campo = new MDN_Campo(colunaNome, notnull, type, obj, primarykey, unique, size, precision);
            return(Campo);
        }
Beispiel #9
0
        /// <summary>
        /// Método que monta a classe de tabela a partir da table criada
        /// </summary>
        /// <param name="nomeTabela"></param>
        /// <param name="tabela"></param>
        /// <returns></returns>
        private static MDN_Table MontaConfiguracaoTabela(string nomeTabela, string tabela, BarraDeCarregamento barra)
        {
            Util.CL_Files.WriteOnTheLog("Backup.MontaConfiguracaoTabela()", Util.Global.TipoLog.DETALHADO);

            MDN_Table table = new MDN_Table(nomeTabela);

            tabela = tabela.Replace("</td>", "");
            tabela = tabela.Replace("</tr>", "");
            tabela = tabela.Replace("<tr>", "|");

            List <string> linhas  = tabela.Split('|').ToList();
            List <string> colunas = new List <string>();

            string lin      = string.Empty;
            int    numlinha = 0;

            foreach (string linha in linhas)
            {
                barra.AvancaBarra(1);
                lin = string.Empty;
                if (string.IsNullOrEmpty(linha.Trim()))
                {
                    continue;
                }

                if (numlinha == 0)
                {
                    numlinha++;
                    continue;
                }

                lin = linha.Replace("|", "");
                lin = lin.Replace("<td class=\"tabhead\" >", "|");
                lin = lin.Replace("<td class=\"tabhead\"  colspan=\"2\">", "|");
                lin = lin.Replace("<td class=\"tabhead\"  colspan=\"3\">", "|");
                lin = lin.Replace("<td class=\"tabhead\"  colspan=\"4\">", "|");
                lin = lin.Replace("<td class=\"tabhead\"  colspan=\"5\">", "|");

                lin = lin.Replace("<td class=\"tabdata\" >", "|");
                lin = lin.Replace("<td class=\"tabdata\"  colspan=\"1\">", "|");
                lin = lin.Replace("<td class=\"tabdata\"  colspan=\"2\">", "|");
                lin = lin.Replace("<td class=\"tabdata\"  colspan=\"3\">", "|");
                lin = lin.Replace("<td class=\"tabdata\"  colspan=\"4\">", "|");
                lin = lin.Replace("<td class=\"tabdata\"  colspan=\"5\">", "|");

                colunas = lin.Trim().Split('|').ToList();
                table.Fields_Table.Add(MontaColuna(colunas, barra));
            }

            return(table);
        }