Ejemplo n.º 1
0
        public static IList <Vendor> GetAll()
        {
            List <Vendor> vendors = new List <Vendor>();

            string selectStatement =
                "SELECT VendorID, Name FROM Vendors";

            SqlConnection connection    = PayablesDb.GetConnection();
            SqlDataReader reader        = null;
            SqlCommand    selectCommand = new SqlCommand(selectStatement, connection);

            try
            {
                connection.Open();
                reader = selectCommand.ExecuteReader();
                int vendorIdOrdinal = reader.GetOrdinal("VendorID");
                int nameOrdinal     = reader.GetOrdinal("Name");

                while (reader.Read())
                {
                    var vendor = new Vendor
                    {
                        VendorId = reader.GetInt32(vendorIdOrdinal),
                        Name     = reader.GetString(nameOrdinal)
                    };
                    vendors.Add(vendor);
                }
            }
            finally
            {
                reader?.Close();
                connection?.Close();
            }
            return(vendors);
        }
Ejemplo n.º 2
0
        public static IList <Invoice> GetAll()
        {
            List <Invoice> invoices = new List <Invoice>();

            string selectStatement =
                "SELECT InvoiceNumber, InvoiceDate, InvoiceTotal, " +
                "PaymentTotal, CreditTotal, DueDate, VendorID " +
                "FROM Invoices";

            SqlConnection connection    = PayablesDb.GetConnection();
            SqlDataReader reader        = null;
            SqlCommand    selectCommand = new SqlCommand(selectStatement, connection);

            try
            {
                connection.Open();
                reader = selectCommand.ExecuteReader();
                int invoiceNumberOrdinal = reader.GetOrdinal("InvoiceNumber");
                int invoiceDateOrdinal   = reader.GetOrdinal("InvoiceDate");
                int invoiceTotalOrdinal  = reader.GetOrdinal("InvoiceTotal");
                int paymentTotalOrdinal  = reader.GetOrdinal("PaymentTotal");
                int creditTotalOrdinal   = reader.GetOrdinal("CreditTotal");
                int dueDateOrdinal       = reader.GetOrdinal("DueDate");
                int vendorIdOrdinal      = reader.GetOrdinal("VendorID");
                while (reader.Read())
                {
                    var invoice = new Invoice
                    {
                        InvoiceNumber = reader.GetString(invoiceNumberOrdinal),
                        InvoiceDate   = reader.GetDateTime(invoiceDateOrdinal),
                        InvoiceTotal  = reader.GetDecimal(invoiceTotalOrdinal),
                        PaymentTotal  = reader.GetDecimal(paymentTotalOrdinal),
                        CreditTotal   = reader.GetDecimal(creditTotalOrdinal),
                        DueDate       = reader.GetDateTime(dueDateOrdinal),
                        VendorId      = reader.GetInt32(vendorIdOrdinal)
                    };
                    invoices.Add(invoice);
                }
            }
            finally
            {
                reader?.Close();
                connection?.Close();
            }
            return(invoices);
        }