public string GerarASPX(string MasterPage, EstruturaSaveRAD estruturaSaveRAD, EstruturaSaveRAD.ClasseCRUDRow ClasseSelecionada)
        {
            Conectar(ClasseSelecionada.StringConexao, ClasseSelecionada.Provider);
            EstruturaSaveRAD.MetodoRow MetodoCrud = CriarMetodoCRUD(estruturaSaveRAD, ClasseSelecionada);
            try{
            if( string.IsNullOrEmpty(MasterPage) )
                MasterPage = "~/MasterPages/Site.master";
            Tabela = ClasseSelecionada.Tabela;
            string Inherits = ClasseSelecionada.NameSpace + "_Manutencao." +  ClasseSelecionada.Tabela + "Form";
            Inherits = Inherits.Replace(".", "_");
            StringBuilder ASPX = new StringBuilder();
            ASPX.AppendFormat(@"<%@ Page Language=""C#"" MasterPageFile=""{0}"" AutoEventWireup=""true"" CodeFile=""Manutencao.{1}Form.aspx.cs"" Inherits=""{2}"" Title=""Untitled Page"" %>", MasterPage, ClasseSelecionada.Tabela, Inherits);
            ASPX.AppendLine();
            string Content = "Content1";
            string ContentPlaceHolderID = "cphPrincipal";
            ASPX.AppendFormat(@"<asp:Content ID=""{0}"" ContentPlaceHolderID=""{1}"" Runat=""Server"">", Content, ContentPlaceHolderID);
            ASPX.AppendLine();
            ASPX.Append(@"<asp:Panel ID=""pnlPesquisa"" runat=""server"" DefaultButton=""btnPesquisa"" GroupingText=""Opções de pesquisa"" Width=""100%"">");
            ASPX.AppendLine();
            ASPX.Append(MontarFiltrosParaHTML(ClasseSelecionada.ObterMetodoSelect()));
            ASPX.Append("<br />");
            ASPX.Append(@"<asp:Panel ID=""pnlItems"" runat=""server"" GroupingText=""Resultados"" Width=""100%"">");
            ASPX.AppendLine();
            ASPX.Append(MontarGridParaHTML(ClasseSelecionada));
            ASPX.AppendLine();
            ASPX.Append(MontarObjectDataSourceParaGridResultado(ClasseSelecionada));
            ASPX.AppendLine();

            ASPX.Append("</asp:Panel>");
            ASPX.AppendLine();
            ASPX.Append(@"<asp:Panel ID=""pnlBotoes"" runat=""server"" HorizontalAlign=""Right"" Width=""100%"">");
            ASPX.AppendLine();
            ASPX.Append(CriarBotaoParaHTML("Incluir", true, false, null));
            ASPX.Append(CriarBotaoParaHTML("Alterar", false, true, null));
            ASPX.Append(CriarBotaoParaHTML("Excluir", false, true, "Tem certeza que deseja realizar a exclusão do item?"));
            ASPX.Append("</asp:Panel>");
            ASPX.Append("</asp:Panel>");
            ASPX.Append("<br />");
            ASPX.Append(MontarObjectDataSourceParaFormView(ClasseSelecionada));
            ASPX.Append("</asp:Content>");
            return ASPX.ToString() ;
            }
            finally
            {
            MetodoCrud.Delete();
            }
        }
        private string MontarObjectDataSourceParaGridResultado(EstruturaSaveRAD.ClasseCRUDRow tabela)
        {
            //<asp:ObjectDataSource ID="odsItems" runat="server" OldValuesParameterFormatString="original_{0}"
            //            SelectMethod="ObterPor_IX_GrupoEmpresarial_Gre_Nome" TypeName="SisCompras.ManutencaoCadastros.Fn.GrupoEmpresarialFn">
            //            <SelectParameters>
            //                <asp:ControlParameter ControlID="tbxPesquisa" Name="Gre_Nome" PropertyName="Text"
            //                    Type="String" />
            //            </SelectParameters>
            //        </asp:ObjectDataSource>

            StringBuilder objectDataSource = new StringBuilder();
            objectDataSource.Append(@"<asp:ObjectDataSource ID=""odsItems"" runat=""server"" OldValuesParameterFormatString=""original_{0}""
                        SelectMethod=""ObterPor_TodosOsFiltros""");
            objectDataSource.AppendLine();
            objectDataSource.AppendFormat(@"TypeName=""{0}.{1}"" UpdateMethod=""Alterar"">",
                tabela.NameSpace,
                tabela.NomeClasse
                );
            objectDataSource.AppendLine();
            EstruturaSaveRAD.MetodoRow metodo = tabela.ObterMetodoSelect();

                objectDataSource.AppendFormat("<{0}>\n{1}\n</{0}>\n",
                    RetornarTipoParametroObjectDataSource(metodo),
                    CriarControlParameterHTML("TextBox", metodo)
                );
                objectDataSource.AppendLine();

            objectDataSource.AppendFormat("</asp:ObjectDataSource>");
            return objectDataSource.ToString();
        }
        private string MontarGridParaHTML(EstruturaSaveRAD.ClasseCRUDRow tabela)
        {
            StringBuilder Grid = new StringBuilder();
            Grid.AppendFormat(@"<x:GridView ID=""gvwItems"" runat=""server"" AutoGenerateColumns=""False"" DataKeyNames=""{0}""
            DataSourceID=""odsItems"" EnableViewState=""False"" OnSelectedIndexChanged=""gvwItems_SelectedIndexChanged""
            Width=""100%"" AscImage="""" AutoGenerateColumnSelect=""RadioButton"" DescImage="""" GenerateColumnSelectIndex=""0"" ModelSelect=""ColumnAndRowSelected""
            WebControlCustomColection=""wccPesquisa"" OnDataBound=""gvwItems_DataBound"">",
                 string.Join(", ", base.PrimaryKeys));
            Grid.AppendLine();
            Grid.AppendFormat("<Columns>\n{0}\n</Columns>\n", CriarBoundFields(tabela.ObterMetodoSelect()));

            Grid.Append(@"</x:GridView>
                    <x:WebControlCustomColection ID=""wccPesquisa"" runat=""server"" WebControl-Capacity=""2"">
                    <x:WebControlCustom Enable=""False"" Text=""btnIncluir"" Visible=""False"" />
                    <x:WebControlCustom Enable=""True"" Text=""btnAlterar"" Visible=""False"" />
                    </x:WebControlCustomColection>");
            Grid.AppendLine();

            return Grid.ToString();
        }