コード例 #1
0
        public List <PaymentDTO> FindByCustomer(int accountID)
        {
            string            queryString = "SELECT * FROM dbo.Payment WHERE accountID = @accountID";
            List <PaymentDTO> results     = new List <PaymentDTO>();
            PaymentDTO        payment;
            AccountDTO        account;
            InvoiceDTO        invoice;

            try
            {
                //The connection is automatically closed at the end of the using block.
                using (SqlConnection con = new SqlConnection(ConnectionString))
                {
                    using (SqlCommand cmd = new SqlCommand(queryString, con))
                    {
                        cmd.Parameters.AddWithValue("@accountID", SqlDbType.Int).Value = accountID;
                        cmd.CommandType = CommandType.Text;
                        con.Open();
                        SqlDataReader reader = cmd.ExecuteReader();
                        while (reader.Read())
                        {
                            account = new AccountDTO();
                            invoice = new InvoiceDTO();
                            payment = new PaymentDTO();
                            payment = GeneratePayment(reader, account, payment, invoice);
                            //return product instance as data object
                            Debug.Print("PaymentDAL: /FindByCustomer/ " + payment.GetId());

                            //add data objects to result-list
                            results.Add(payment);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                e.GetBaseException();
            }
            return(results);
        }
コード例 #2
0
        public PaymentDTO FindBy(int id)
        {
            PaymentDTO payment;
            AccountDTO account;
            InvoiceDTO invoice;
            string     queryString = "SELECT * FROM dbo.Payment WHERE paymentID = @id";

            try
            {
                //The connection is automatically closed at the end of the using block.
                using (SqlConnection con = new SqlConnection(ConnectionString))
                {
                    using (SqlCommand cmd = new SqlCommand(queryString, con))
                    {
                        cmd.Parameters.AddWithValue("@id", SqlDbType.Int).Value = id;
                        cmd.CommandType = CommandType.Text;
                        con.Open();
                        SqlDataReader reader = cmd.ExecuteReader();
                        if (reader.Read())
                        {
                            account = new AccountDTO();
                            invoice = new InvoiceDTO();
                            payment = new PaymentDTO();
                            payment = GeneratePayment(reader, account, payment, invoice);
                            //return product instance as data object
                            Debug.Print("PaymentDAL: /FindBy/ " + payment.GetId());
                            return(payment);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                e.GetBaseException();
                Debug.Print(e.ToString());
            }
            return(null);
        }