コード例 #1
0
ファイル: TicketItemOption.cs プロジェクト: zaieda/TemPOS
        public static TicketItemOption Add(int ticketItemId, int itemOptionId,
                                           TicketItemOptionType type, int changeCount)
        {
            TicketItemOption result = null;
            short            year   = DayOfOperation.CurrentYear;
            YearId           ticketItemPrimaryKey = new YearId(year, ticketItemId);

            changeCount = changeCount.Clamp(0, 255);

            // Cache old before making a change
            TicketItem ticketItem = TicketItem.Get(ticketItemPrimaryKey);

            if (!ticketItem.IsTicketItemOptionsChanged)
            {
                TicketItem.CacheTicketItemOptions(ticketItem);
            }

            SqlConnection cn = GetConnection();

            using (SqlCommand sqlCmd = new SqlCommand("AddTicketItemOption", cn))
            {
                sqlCmd.CommandType = CommandType.StoredProcedure;
                BuildSqlParameter(sqlCmd, "@TicketItemOptionItemOptionId", SqlDbType.Int, itemOptionId);
                BuildSqlParameter(sqlCmd, "@TicketItemOptionTicketItemId", SqlDbType.Int, ticketItemId);
                BuildSqlParameter(sqlCmd, "@TicketItemOptionType", SqlDbType.TinyInt, type);
                BuildSqlParameter(sqlCmd, "@TicketItemOptionChangeCount", SqlDbType.TinyInt, changeCount);
                BuildSqlParameter(sqlCmd, "@TicketItemOptionYear", SqlDbType.SmallInt, year);
                BuildSqlParameter(sqlCmd, "@TicketItemOptionId", SqlDbType.Int, ParameterDirection.ReturnValue);
                if (sqlCmd.ExecuteNonQuery() > 0)
                {
                    result = new TicketItemOption(new YearId(year, Convert.ToInt32(sqlCmd.Parameters["@TicketItemOptionId"].Value)),
                                                  itemOptionId, ticketItemId, type, changeCount);
                }
            }
            FinishedWithConnection(cn);

            if (result != null)
            {
                SetTicketItemIsChanged(ticketItem);
            }

            // Reduce the inventory
            TicketItemOption.AdjustInventory(result, ticketItem.Quantity, false);

            return(result);
        }
コード例 #2
0
ファイル: TicketItem.cs プロジェクト: zaieda/TemPOS
        public static void AdjustInventory(TicketItem ticketItem, bool increase,
                                           int?difference = null)
        {
            int quantity =
                (difference != null ? difference.Value :
                 (ticketItem.QuantityPending != null ? ticketItem.QuantityPending.Value :
                  ticketItem.Quantity));

            foreach (ItemIngredient itemIngredient in
                     ItemIngredient.GetAll(ticketItem.ItemId))
            {
                PosModelHelper.AdjustInventoryByIngredient(itemIngredient.IngredientId,
                                                           increase, itemIngredient.Amount * quantity,
                                                           itemIngredient.MeasurementUnit);
            }

            foreach (TicketItemOption ticketItemOption in
                     TicketItemOption.GetAll(ticketItem.PrimaryKey))
            {
                TicketItemOption.AdjustInventory(ticketItemOption, quantity,
                                                 increase);
            }
        }