public void AddPartSaleToDatabase() { MyConnection currentConnection = new MyConnection(); SqlConnection connection = currentConnection.CurrentConnection; SqlCommand command; string query = "INSERT INTO PartSale(PartRef, CustomerRef, SaleDate, Price, Quantity, Notes) VALUES(@PartRef, @CustomerRef, @SaleDate, @Price, @Quantity, @Notes)"; command = new SqlCommand(query, connection); command.Parameters.AddWithValue("@PartRef", PartRef); command.Parameters.AddWithValue("@CustomerRef", CustomerRef); command.Parameters.AddWithValue("@SaleDate", SaleDate.ToShortDateString()); command.Parameters.AddWithValue("@Price", Price.ToString()); command.Parameters.AddWithValue("@Quantity", Quantity.ToString()); command.Parameters.AddWithValue("@Notes", Notes); connection.Open(); command.ExecuteNonQuery(); connection.Close(); Part.Quantity -= Quantity; Part.UpdatePart(); }
public void UpdatePartSale(PartSale oldPartSale) { MyConnection currentConnection = new MyConnection(); SqlConnection connection = currentConnection.CurrentConnection; SqlCommand command; string query = "UPDATE PartSale SET SaleDate = @SaleDate, Price = @Price, Quantity = @Quantity, Notes = @Notes WHERE PartSaleID = @PartSaleID"; command = new SqlCommand(query, connection); command.Parameters.AddWithValue("@PartRef", PartRef); command.Parameters.AddWithValue("@CustomerRef", CustomerRef); command.Parameters.AddWithValue("@SaleDate", SaleDate.ToShortDateString()); command.Parameters.AddWithValue("@Price", Price.ToString()); command.Parameters.AddWithValue("@Quantity", Quantity.ToString()); command.Parameters.AddWithValue("@Notes", Notes); command.Parameters.AddWithValue("@PartSaleID", PartSaleID); connection.Open(); command.ExecuteNonQuery(); connection.Close(); Part.Quantity = Part.Quantity - (Quantity - oldPartSale.Quantity); }
public void AssignFormattedDate() { FormattedSaleDate = SaleDate.ToShortDateString(); }
public override string ToString() => $"{Quantity} @ {SalePrice.ToCurrency(2)} on {SaleDate.ToShortDateString()}";