Example #1
0
        public StringBuilder GenerateClassCode(LanguajeType Languaje, bool IsMobile, bool UseFramework2)
        {
            try
            {
                var cnn        = _DataBaseDataSet.TBL_Connection[0];
                var catalogos  = CMData.DataBase.DataBase.GetDistinctRows(_DataBaseDataSet.TBL_Object.Select("fk_Connection = " + cnn.id_Connection), "Catalog_Name");
                var SourceCode = new StringBuilder();

                string Catalog          = catalogos.Rows[0]["Catalog_Name"].ToString();
                string CatalogClassName = FormatCode.ToIdentifier(Catalog);

                switch (Languaje)
                {
                case LanguajeType.VB:
                    SourceCode = VisualBasicWriter.WriteDataBaseManagerDesigner(cnn, CatalogClassName, Catalog, "", _DataBaseDataSet, IsMobile, UseFramework2);
                    break;

                case LanguajeType.CSharp:
                    SourceCode = CSharpWriter.WriteDataBaseManagerDesigner(cnn, CatalogClassName, Catalog, "", _DataBaseDataSet, IsMobile, UseFramework2);
                    break;
                }

                return(SourceCode);
            }
            catch (Exception ex)
            {
                _Log.AppendLine(ex.Message);
            }

            return(new StringBuilder());
        }
Example #2
0
        public void GenerateClassCode(XsdDataBase.TBL_ConnectionRow nConnection, string nPath, string nNamespaceMap, LanguajeType Languaje, bool IsMobile, bool UseFramework2)
        {
            //Crear el Database Manager
            var catalogos = CMData.DataBase.DataBase.GetDistinctRows(_DataBaseDataSet.TBL_Object.Select("fk_Connection = " + nConnection.id_Connection), "Catalog_Name");

            foreach (DataRow catalogo in catalogos.Rows)
            {
                try
                {
                    var CatalogConfig = _DataBaseDataSet.TBL_Catalog.FindByfk_ConnectionCatalog_Name(nConnection.id_Connection, catalogo["Catalog_Name"].ToString());

                    var fileName         = nPath.TrimEnd('\\') + "\\" + CatalogConfig.Class_File_Name + "DBManager";
                    var fileNameDesigner = nPath.TrimEnd('\\') + "\\" + CatalogConfig.Class_File_Name + "DBManager.Designer";

                    switch (Languaje)
                    {
                    case LanguajeType.VB:
                        fileName         += ".vb";
                        fileNameDesigner += ".vb";
                        break;

                    case LanguajeType.CSharp:
                        fileName         += ".cs";
                        fileNameDesigner += ".cs";
                        break;
                    }

                    var importsCode        = getImports(Languaje);
                    var SourceCode         = new StringBuilder();
                    var SourceCodeDesigner = new StringBuilder();

                    switch (Languaje)
                    {
                    case LanguajeType.VB:
                        SourceCode         = VisualBasicWriter.WriteDataBaseManager(nConnection, CatalogConfig.Class_Name, nNamespaceMap);
                        SourceCodeDesigner = VisualBasicWriter.WriteDataBaseManagerDesigner(nConnection, CatalogConfig.Class_Name, CatalogConfig.Catalog_Name, nNamespaceMap, _DataBaseDataSet, IsMobile, UseFramework2);
                        break;

                    case LanguajeType.CSharp:
                        SourceCode         = CSharpWriter.WriteDataBaseManager(nConnection, CatalogConfig.Class_Name, nNamespaceMap);
                        SourceCodeDesigner = CSharpWriter.WriteDataBaseManagerDesigner(nConnection, CatalogConfig.Class_Name, CatalogConfig.Catalog_Name, nNamespaceMap, _DataBaseDataSet, IsMobile, UseFramework2);
                        break;
                    }

                    StreamWriter sw = null;

                    // DiseƱador
                    sw = new System.IO.StreamWriter(fileNameDesigner);

                    foreach (var imp in importsCode)
                    {
                        sw.WriteLine(imp);
                    }

                    sw.WriteLine();

                    sw.Write(SourceCodeDesigner.ToString());
                    sw.Flush();
                    sw.Close();

                    // Codigo usuario
                    if (!File.Exists(fileName))
                    {
                        sw = new System.IO.StreamWriter(fileName);

                        foreach (var imp in importsCode)
                        {
                            sw.Write(imp + ControlChars.CrLf);
                        }

                        sw.Write(SourceCode.ToString());
                        sw.Flush();
                        sw.Close();
                    }
                }
                catch (Exception ex)
                {
                    _Log.AppendLine(ex.Message);
                }
            }
        }