public List <InvoiceDO> ViewInvoices() { //get list List <InvoiceDO> allInvoices = new List <InvoiceDO>(); //defines variables SqlConnection connection = null; SqlDataAdapter adapter = null; DataTable table = new DataTable(); SqlCommand command = null; try { //obtains the connection to database connection = new SqlConnection(_ConnectionString); command = new SqlCommand("VIEW_INVOICE", connection); command.CommandType = CommandType.StoredProcedure; connection.Open(); adapter = new SqlDataAdapter(command); adapter.Fill(table); allInvoices = InvoiceMap2.DataTableToList(table); } catch (Exception ex) { logger.Log("Fatal", ex.Source, ex.TargetSite.ToString(), ex.Message, ex.StackTrace); throw ex; } finally { //if not null close and dispose if (connection != null) { connection.Close(); connection.Dispose(); } if (adapter != null) { adapter.Dispose(); } } return(allInvoices); }
public InvoiceDO ViewInvoiceByID(Int64 InvoiceID) { //get list InvoiceDO invoice = new InvoiceDO(); //defines variables SqlConnection connection = null; SqlDataAdapter adapter = null; DataTable table = new DataTable(); SqlCommand command = null; try { //gets connection to database connection = new SqlConnection(_ConnectionString); command = new SqlCommand("VIEW_INVOICE_BY_ID", connection); command.CommandType = CommandType.StoredProcedure; connection.Open(); command.Parameters.AddWithValue("@InvoiceID", InvoiceID); adapter = new SqlDataAdapter(command); adapter.Fill(table); invoice = InvoiceMap2.DataTableToList(table).FirstOrDefault(); } catch (Exception ex) { logger.Log("Fatal", ex.Source, ex.TargetSite.ToString(), ex.Message, ex.StackTrace); throw ex; } finally { //if not null close and dispose if (connection != null) { connection.Close(); connection.Dispose(); } } return(invoice); }
public List <InvoiceDO> ViewInvoiceByUserID(long UserID) { // get list and define the variables List <InvoiceDO> allInvoices = new List <InvoiceDO>(); SqlConnection connection = null; SqlDataAdapter adapter = null; DataTable table = new DataTable(); SqlCommand command = null; try { //opens connectio and uses the parameter of ID connection = new SqlConnection(_ConnectionString); command = new SqlCommand("View_Invoice_By_UserID", connection); command.CommandType = CommandType.StoredProcedure; connection.Open(); command.Parameters.AddWithValue("@UserID", UserID); adapter = new SqlDataAdapter(command); adapter.Fill(table); allInvoices = InvoiceMap2.DataTableToList(table); } catch (Exception ex) { logger.Log("Fatal", ex.Source, ex.TargetSite.ToString(), ex.Message, ex.StackTrace); throw ex; } finally { // if null close and dispose if (connection != null) { connection.Close(); connection.Dispose(); } } return(allInvoices); }