public Transaction GetTransaction(string code) { SqlConnection conn = connection.GetConnection(); conn.Open(); ClientDAO clientDAO = new ClientDAO(); ProductDAO productDAO = new ProductDAO(); DataTable dt = new DataTable(); Transaction transaction = new Transaction(); try { string req = "select * from transactions where code=@code"; SqlCommand cmd = new SqlCommand(req, conn); cmd.Parameters.AddWithValue("@code", code); SqlDataAdapter adapter = new SqlDataAdapter(cmd); adapter.Fill(dt); DataRow row = (from trans in dt.AsEnumerable() where trans.Field <string>("code") == code select trans).First(); transaction.TransactionDate = row.Field <DateTime>("transactionDate"); transaction.Code = row.Field <string>("code"); transaction.Client = clientDAO.GetClient(row.Field <string>("clientID")); transaction.Product = productDAO.GetProduct(row.Field <string>("productID")); } catch (Exception e) { } finally { conn.Close(); } return(transaction); }
public List <Transaction> getTransactionsListByProductID(string productid) { SqlConnection conn = connection.GetConnection(); conn.Open(); DataTable dt = new DataTable(); List <Transaction> list = null; ClientDAO clientDAO = new ClientDAO(); ProductDAO productDAO = new ProductDAO(); try { string req = "select * from transactions where productID=@productid"; SqlCommand cmd = new SqlCommand(req, conn); cmd.Parameters.AddWithValue("@productid", productid); SqlDataAdapter adapter = new SqlDataAdapter(cmd); adapter.Fill(dt); dt.AsEnumerable(); if (dt.Rows.Count != 0) { list = new List <Transaction>(); foreach (DataRow row in dt.AsEnumerable()) { Transaction transaction = new Transaction(); transaction.TransactionDate = row.Field <DateTime>("transactionDate"); transaction.Code = row.Field <string>("code"); transaction.Client = clientDAO.GetClient(row.Field <string>("clientID")); transaction.Product = productDAO.GetProduct(row.Field <string>("productID")); transaction.Quantity = row.Field <int>("quantity"); list.Add(transaction); } } else { throw (new PAS_DE_TRANSACTION_EXCEPTION("The Transactions List Is Currently Empty")); } } catch (Exception e) { } finally { conn.Close(); } return(list); }