main.cs :  » Persistence-Frameworks » Advanced-Data-Provider » Advanced » Data » Provider » Samples » Terminal » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Persistence Frameworks » Advanced Data Provider 
Advanced Data Provider » Advanced » Data » Provider » Samples » Terminal » main.cs
#region Copyright 
/*
 * LGPL Licence
 * Created by sri_canesh@users.sourceforge.net to Adp Project
 * Especial thanks: Eduardo Canuto and Melitta(Capuccino dust) 
 */  
#endregion

using System;
using System.Collections.Specialized;
using System.Configuration;
using Advanced.Data.Provider.Samples;


namespace Advanced.Data.Provider.Samples.Terminal{
  /// <summary>
  /// Demonstrao do ADP em modo console
  /// </summary>
  class Sample
  {
    static ADPShow show = new ADPShow();  
    /// <summary>
    /// O show comea aqui
    /// </summary>
    [STAThread]
    static void Main(string[] args)
    {
      
        
      string cmdline = "";
      string strcmd = "";
      string strpar = "";
      Console.WriteLine("ADP Samples - How to use ADP");
      Console.WriteLine("Copyright (c) 2003-2004 Advanced.NET Team        Initial version by Sri Canesh");      
      Console.WriteLine("\nADP Team prefere Mono");

      if(args.Length > 0)
      {
        Console.WriteLine("Trying connect to {0}",args[0]);
        Connect(args[0]);        
      }
      
      Help();

      // Prompt looping!
      while (true)
      {
        Console.Write(">");  cmdline = Console.ReadLine().Trim() + " ";
        int i = cmdline.IndexOf(" ");
        strcmd = cmdline.Substring(0,i);
        strpar = cmdline.Substring(i).Trim();

        switch (strcmd.ToLower().Trim())
        {
          case "":
            break;
          case "exit":
            Console.WriteLine("Good bye!");
            return;
          case "help":
            Help();
            break;
          case "providers":
            //SqlProviders();
            break;
          case "strings":
            ShowStrings();
            break;
          case "connect":
            Connect(strpar);
            break;
          case "create_tables":
            CreateTables();
            break;
          case "populate":
            Populate();
            break;
          case "count_artists":
            CountArtists();
            break;
          case "show_albuns":
            ShowAlbuns(false);
            break;
          case "show_albuns_close":   //undocumented
            ShowAlbuns(true);
            Help();
            break;
          case "show_artists":
            ShowArtists();
            break;
          case "how_many_albuns":
            ShowAlbunsByRecord();
            break;
          case "search":
            SearchAlbum();
            break;
          case "bot":
            Bot();
            break;
          case "close":
            //SqlClose();
            break;
          default:
            //SqlCommand(cmdline);
            break;
        }
      }
      
    }

    static void Help()
    {
      Console.WriteLine("");
      Console.WriteLine("Type:");      
      // opo para mostrar as strings pr-configuradas no app.info
      Console.WriteLine("  strings           - Show connection strings in app.info");
      // opo para criar a conexao ao banco de dados
      Console.WriteLine("  connect [connstr] - Connect to [connstr] database.");
      // opes que so exibidas apenas se houvesse sucesso na conexao com o banco
      if(show.IsOpen())
      {
        // opo para criar as tabelas na base de dados. Exemplo da do mtodo AdpCommand.ExecuteNonQuery())
        Console.WriteLine("  create_tables     - Create tables (example of AdpCommand.ExecuteNonQuery");      
        // opo para popular as tabelas. Exemplo de ExecuteNonQuery que retorna numero de registros afetados
        Console.WriteLine("  populate          - Populate tables with default values ");
        // opo para mostrar o nmero de artistas na tabela adp_artists. Exemplo de uso de ExecuteScalar()
        Console.WriteLine("  count_artists     - Show number of rows in table adp_artists");
        // opcao para mostrar os albus da tabela adp_albuns. Exemplo de uso de ExecuteReader()
        Console.WriteLine("  show_albuns       - Show albuns of table adp_albuns");
        // opcao para mostrar os artistas da tabela adp_artists. Exemplo de uso de ExecuteDataSet()
        Console.WriteLine("  show_artists      - Show artists of table adp_artists");
        // opcao para mostrar a quantidade de albuns por gravadora
        Console.WriteLine("  how_many_albuns   - Show Albuns quantity by record");
        // opcao para mostrar os albuns que atendem determinado critrio. Exemplo de CreateParameter
        Console.WriteLine("  search            - Search album ");
        // opcao para executar os testes em srie
        Console.WriteLine("  bot               - Execute all options");
        // opo para fechar conexes ativas
        Console.WriteLine("  close             - Close active connection.");      
      }
      // mostra o menu de opes
      Console.WriteLine("  help              - Show this message.");
      // sai do demonstrativo
      Console.WriteLine("  exit              - Exit AdpShow");
      Console.WriteLine();
    }

    /// <summary>
    /// Cria a conexo com o banco de daods
    /// </summary>
    /// <param name="connstr"></param>
    static void Connect(string connStr)
    {
      // Para saber como criar uma conexo via ADP, verifique o mtodo ConnectDB da classe ADPShow
      if(show.ConnectDB(connStr))
      {
        Console.WriteLine("Conected\n");
        Help();
      }
      else
        Console.WriteLine(show.LastError + "\n");


    }

    /// <summary>
    /// Mostra as conexes pr-configuradas no app.info
    /// </summary>
    static void ShowStrings()
    {
      System.Collections.Specialized.NameValueCollection keys;
      keys = System.Configuration.ConfigurationSettings.AppSettings ;
      foreach(string str in keys.AllKeys)
      {
        Console.WriteLine("{0}: {1} \n",str, keys.Get(str));
      }      
    }

    /// <summary>
    /// Cria as tabelas no banco de dados
    /// Exemplo de utilizao da funo ExecuteNonQuery
    /// </summary>
    static void CreateTables()
    {
      Console.WriteLine(show.CreateTables()+"\n");      
    }

    /// <summary>
    /// Popula as tabelas com valores default
    /// Exemplo de utilizao da funo ExecuteNonQuery retornando registros afetados
    /// </summary>
    static void Populate()
    {
      Console.WriteLine(show.Populate()+"\n");      
    }

    /// <summary>
    /// Mostra o total de artistas 
    /// Exemplo de utilizacao da funcao ExecuteScalar
    /// </summary>
    static void CountArtists()
    {
      Console.WriteLine(show.ReturnRowsInTable()+"\n");
    }

    /// <summary>
    /// Mostra os albuns da tabela adp_albus
    /// Exemplo de utilizacao da funcao ExecuteReader
    /// Se for passado true ele passa CommandBehavior.CloseConnection
    /// </summary>
    static void ShowAlbuns(bool close)
    {
      Console.WriteLine(show.ShowAlbuns(close)+"\n");
    }

    /// <summary>
    /// Mostra os albuns da tabela adp_artists
    /// Exemplo de utilizacao da funcao ExecuteDataset
    /// </summary>
    static void ShowArtists()
    {
      Console.WriteLine(show.ShowArtists()+"\n");
    }

    /// <summary>
    /// Mostra a quantidade de albuns por gravadora
    /// Exemplo de utilizacao da funcao ExecuteDataTable()
    /// </summary>
    static void ShowAlbunsByRecord()
    {
      Console.WriteLine(show.ShowAlbunsByRecord()+"\n");
    }

    /// <summary>
    /// Mostra os albuns que atendem ao critrio de busca.
    /// Exemplo de uso de parmetros
    /// </summary>
    static void SearchAlbum()
    {
      string cmdline;
      Console.Write("Type argument do search>");  cmdline = Console.ReadLine().Trim() + " ";
      Console.WriteLine(show.SearchAlbum(cmdline)+"\n");
    }

    /// <summary>
    /// Executa os testes automaticamente
    /// </summary>
    static void Bot()
    {
       Console.WriteLine("Create tables ... \n"+ show.CreateTables()+"\n");
       Console.WriteLine("Populate tables ...\n"+ show.Populate()+"\n");
       Console.WriteLine(show.ReturnRowsInTable()+"\n");
       Console.WriteLine(show.ShowAlbuns(false)+"\n");
       Console.WriteLine(show.ShowArtists()+"\n");
       Console.WriteLine(show.ShowAlbunsByRecord()+"\n");
       Console.WriteLine(show.SearchAlbum("the")+"\n");

    }
    

  }
}

www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.