コード例 #1
0
        /// <summary>
        /// Add a row to the inventory list. Only allows it if there is no matching
        /// item code.
        /// </summary>
        /// <param name="primKey"></param>
        /// <param name="itemDesc"></param>
        /// <param name="cost"></param>
        /// <returns></returns>
        ///
        #endregion

        #region Delete button
        /// <summary>
        /// This is the logic behind the delete button on the InventoryWindow page.
        /// Takes the selected row, sends the primary key letter, compares it with LineItems
        /// invoice items, if there are associations between those ItemCodes and invoices
        /// the user is unable to delete the item. Otherwise the user can.
        /// </summary>
        /// <param name="itemCodeSelected"></param>
        /// <returns></returns>
        public Boolean DeleteButtonLogic(string itemCodeSelected)
        {
            try
            {
                //Retrieves lineItem table ItemCodes
                LineItem_ItemCodes = clsPopInventory.GetLineItems_ItemCodes();

                //If count >= 1, there is a value in LineItems that matches
                int delCount = 0;

                //Number of rows changed if needed
                int num = 0;

                //Returns if the delete was successful or not
                Boolean result = true;

                foreach (string ic in LineItem_ItemCodes)
                {
                    if (ic.Equals(itemCodeSelected))
                    {
                        delCount++;
                    }
                }

                if (delCount > 0)
                {
                    result = false;
                }
                else
                {
                    //Executes the delete item statement
                    num = db.ExecuteNonQuery(SQLQueries.DeleteInventoryRow(itemCodeSelected));
                }
                return(result);
            }
            catch (Exception ex)
            {
                //Just throw the exception
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." +
                                    MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
            }
        }