Exemplo n.º 1
0
        protected void ApplyTemplate(ITableTransformation command, string baseFolder, string label, List <TableModel> tables = null)
        {
            command.NameSpace          = _projectModel.nameSpace;
            command.ConnectionStringID = _projectModel.connectionStringID;

            if (tables == null)
            {
                tables = _projectModel.Tables;
            }
            foreach (var tabela in tables)
            {
                string dtoContent = command.ApplyTemplate(tabela, _projectModel.Tables);
                if (string.IsNullOrEmpty(dtoContent) == false)
                {
                    string fileName = Path.Combine(baseFolder + "\\" + command.FileName + command.Extension);
                    File.WriteAllText(fileName, dtoContent);
                    _mensagens.Add(new ProjectConsoleMessages()
                    {
                        data = DateTime.Now, mensagem = string.Format("{0} [{1}] Criado!", label, fileName), erro = false
                    });
                }
                else
                {
                    _mensagens.Add(new ProjectConsoleMessages()
                    {
                        data = DateTime.Now, mensagem = string.Format("{0} [{1}] Ignorado!", label, tabela.Name), erro = false
                    });
                }
            }
        }
Exemplo n.º 2
0
        private void btnPreview_Click(object sender, EventArgs e)
        {
            if (cboTemplate.SelectedItem == null || cboTemplate.SelectedItem.ToString() == "")
            {
                return;
            }

            if (lstObjects.SelectedItem == null || lstObjects.SelectedItem.ToString() == "")
            {
                return;
            }

            try
            {
                ITableTransformation cmd = (ITableTransformation)orm.AvailableTableTemplates(Environment.CurrentDirectory).Where(t => t.CommandID == cboTemplate.SelectedItem.ToString()).Single();
                cmd.NameSpace = txtNameSpace.Text;
                var table = projectModel.Tables.Where(t => t.Name == lstObjects.SelectedItem.ToString()).FirstOrDefault();
                if (table == null)
                {
                    table = orm.Tables.Where(t => t.Name == lstObjects.SelectedItem.ToString()).FirstOrDefault();
                }
                if (table == null)
                {
                    txtConsole.Text = string.Format("Tabela [{0}] não encontrada!", lstObjects.SelectedItem.ToString());
                }
                else
                {
                    Form2 frm = new Form2();
                    frm.PreviewCode = cmd.ApplyTemplate(table, projectModel.Tables);
                    txtConsole.Text = FormatarConsole(cmd.Mensagens);
                    frm.Show();
                }
            }
            catch (Exception err)
            {
                txtConsole.Text = string.Format("Erro no processamento!Msg: {0}", err.Message);
            }
        }