public List <IShipmentInfoDO> ViewAllShipments() { //create new list to store several objects from db List <IShipmentInfoDO> viewList = new List <IShipmentInfoDO>(); try { //create connection using (SqlConnection connectionToSQL = new SqlConnection(connectionString)) //create a command using (SqlCommand command = new SqlCommand("VIEW_ALL_SHIPMENTS", connectionToSQL)) { try { connectionToSQL.Open(); //use reader SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { //intantiate new shipment data object to fill from reader IShipmentInfoDO shipment = new ShipmentDO(); //shipment.info is set to info from database shipment.ShipmentID = reader.GetInt64(0); shipment.LocationID = reader.GetInt64(1); shipment.Product = reader.GetString(2); shipment.ProducerID = reader.GetInt64(3); shipment.QuantityInBu = reader.GetInt64(4); shipment.PricePerBushel = reader.GetDecimal(5); //add each row, as its own object, to this list viewList.Add(shipment); } } catch (Exception e) { //throw out to next try catch to log, avoid logging same error 2 times throw e; } finally { connectionToSQL.Close(); connectionToSQL.Dispose(); } } } catch (Exception e) { //write error to file and pass to next level up (presentation layer) ErrorLogging.LogError(e); throw e; } finally { } return(viewList); }
public List <IShipmentInfoDO> ViewAllShipments() { //create new list to store several interface objects List <IShipmentInfoDO> viewList = new List <IShipmentInfoDO>(); try { //create connection using (SqlConnection connectionToSQL = new SqlConnection(connectionString)) //create a command using (SqlCommand command = new SqlCommand("VIEW_ALL_SHIPMENTS", connectionToSQL)) { try { connectionToSQL.Open(); //use reader SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { IShipmentInfoDO location = new ShipmentDO(); location.LocationID = reader.GetInt64(0); location.Product = reader.GetString(1); location.ProducerID = reader.GetInt64(2); location.QuantityInBu = reader.GetInt64(3); location.PricePerBushel = reader.GetDecimal(4); viewList.Add(location); } } catch (Exception e) { ErrorLogging.logError(e); throw e; } finally { connectionToSQL.Close(); connectionToSQL.Dispose(); } } } catch (Exception e) { ErrorLogging.logError(e); throw e; } finally { } return(viewList); }
public static IShipmentInfoDO MapPOtoDO(ShipmentPO iFrom) { IShipmentInfoDO newshipment = new ShipmentDO(); newshipment.ShipmentID = iFrom.ShipmentID; newshipment.LocationID = iFrom.LocationID; newshipment.Product = iFrom.Product; newshipment.ProducerID = iFrom.ProducerID; newshipment.QuantityInBu = iFrom.QuantityInBu; newshipment.PricePerBushel = iFrom.PricePerBushel; return(newshipment); }
public IShipmentInfoDO ViewShipmentByID(long ShipmentID) { IShipmentInfoDO viewshipment = new ShipmentDO(); try { //using statements for connection and command using (SqlConnection connectionToSQL = new SqlConnection(connectionString)) using (SqlCommand command = new SqlCommand("VIEW_SHIPMENT_BY_ID", connectionToSQL)) { try { command.CommandTimeout = 35; command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@ShipmentID", ShipmentID); connectionToSQL.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { viewshipment.ShipmentID = reader.GetInt64(0); viewshipment.LocationID = reader.GetInt64(1); viewshipment.Product = reader.GetString(2); viewshipment.ProducerID = reader.GetInt64(3); viewshipment.QuantityInBu = reader.GetInt64(4); viewshipment.PricePerBushel = reader.GetDecimal(5); } } catch (Exception e) { throw e; } finally { } } } catch (Exception e) { ErrorLogging.LogError(e); throw e; } finally { //nothing } return(viewshipment); }
public List <IShipmentInfoDO> ViewShipmentsByLocation(long LocationID) { //create new list to store several objects from db List <IShipmentInfoDO> viewList = new List <IShipmentInfoDO>(); try { //create connection using (SqlConnection connectionToSQL = new SqlConnection(connectionString)) //create a command using (SqlCommand command = new SqlCommand("VIEW_SHIPMENTS_BY_LOCATION", connectionToSQL)) { try { command.CommandType = CommandType.StoredProcedure; command.CommandTimeout = 35; connectionToSQL.Open(); //pass in Location ID to search by that column command.Parameters.AddWithValue("@LocationID", LocationID); //use reader SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { //intantiate new shipment data object to fill from reader IShipmentInfoDO shipment = new ShipmentDO(); //shipment.info is set to info from database shipment.ShipmentID = reader.GetInt64(0); shipment.LocationID = reader.GetInt64(1); shipment.Product = reader.GetString(2); shipment.ProducerID = reader.GetInt64(3); shipment.QuantityInBu = reader.GetInt64(4); shipment.PricePerBushel = reader.GetDecimal(5); //add each row, as its own object, to this list viewList.Add(shipment); } } catch (Exception e) { throw e; } finally { connectionToSQL.Close(); connectionToSQL.Dispose(); } } } catch (Exception e) { //write error to file and pass to next level up (presentation layer) ErrorLogging.LogError(e); throw e; } finally { } return(viewList); }