Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 public void AssignFormattedDate()
 {
     FormattedSaleDate = SaleDate.ToShortDateString();
 }
Ejemplo n.º 4
0
 public override string ToString() => $"{Quantity} @ {SalePrice.ToCurrency(2)} on {SaleDate.ToShortDateString()}";