Exemple #1
0
        public void Execute(string conLink)
        {
            int        ano, MONTANTEMINIMO, MONTANTEMAXIMO;
            List <int> prms = new List <int>();

            prms = InfoGetter(prms);

            try
            {
                ano            = prms[0];
                MONTANTEMINIMO = prms[1];
                MONTANTEMAXIMO = prms[2];
            }
            catch (FormatException)
            {
                Console.WriteLine("Alguns parametros estavam errados.");
                return;
            }
            using (SqlConnection con = new SqlConnection(conLink))
            {
                con.Open();
                SqlTransaction tran = con.BeginTransaction();
                try
                {
                    using (SqlCommand cmd = con.CreateCommand())
                    {
                        cmd.Transaction = tran;
                        cmd.CommandText = "select * from dbo.FaturasPorAno(@ANO,@MONTANTEMINIMO,@MONTANTEMAXIMO)";
                        cmd.Parameters.Add("@ANO", SqlDbType.Int).Value = ano;
                        cmd.Parameters.Add("@MONTANTEMINIMO", SqlDbType.SmallMoney).Value = MONTANTEMINIMO;
                        cmd.Parameters.Add("@MONTANTEMAXIMO", SqlDbType.SmallMoney).Value = MONTANTEMAXIMO;
                        using (SqlDataReader dr = cmd.ExecuteReader())
                        {
                            List <string> columnNames = TablePrinter.Getcolumns(dr).ToList();

                            TablePrinter.PrintTable(columnNames);

                            while (dr.Read())
                            {
                                Console.Write(Convert.ToInt32(dr[columnNames[0]]) + " - " +
                                              Convert.ToInt32(dr[columnNames[1]]) + " - " +
                                              Convert.ToInt32(dr[columnNames[2]]) + " - " +
                                              Convert.ToInt32(dr[columnNames[3]]));
                                Console.WriteLine();
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                tran.Commit();
                con.Close();
            }
        }
        public void Execute(string conLink)
        {
            DateTime      inicio, fim;
            List <string> prms = new List <string>();

            prms = InfoGetter(prms);

            try
            {
                inicio = Convert.ToDateTime(prms[0]);
                fim    = Convert.ToDateTime(prms[1]);
            }
            catch (FormatException)
            {
                Console.WriteLine("Alguns parametros estavam errados.");
                return;
            }
            using (SqlConnection con = new SqlConnection(conLink))
            {
                con.Open();
                SqlTransaction tran = con.BeginTransaction();
                try
                {
                    using (SqlCommand cmd = con.CreateCommand())
                    {
                        cmd.Transaction = tran;
                        cmd.CommandText = "select * from dbo.EventosCancelados(@INICIO,@FIM)";
                        cmd.Parameters.Add("@INICIO", SqlDbType.Date).Value = inicio;
                        cmd.Parameters.Add("@FIM", SqlDbType.Date).Value    = fim;

                        using (SqlDataReader dr = cmd.ExecuteReader())
                        {
                            List <string> columnNames = TablePrinter.Getcolumns(dr).ToList();

                            TablePrinter.PrintTable(columnNames);

                            while (dr.Read())
                            {
                                Console.Write(Convert.ToInt32(dr[columnNames[0]]) + " - ");
                                Console.Write(Convert.ToInt32(dr[columnNames[1]]) + " - ");
                                Console.Write(Convert.ToInt32(dr[columnNames[2]]) + " - ");
                                Console.Write(Convert.ToInt32(dr[columnNames[3]]) + " - ");
                                Console.WriteLine();
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                tran.Commit();
                con.Close();
            }
        }