コード例 #1
0
        /// <summary>
        /// Logic for the add button. Adds items to the inventory list.
        /// </summary>
        /// <param name="primKey"></param>
        /// <param name="itemDesc"></param>
        /// <param name="cost"></param>
        /// <returns></returns>
        public Boolean AddInventoryRow(string primKey, string itemDesc, decimal cost)
        {
            try
            {
                clsUpdateInventory clsPopInv = new clsUpdateInventory();

                // Returned if row was added or not
                Boolean rowAdded = false;

                // In case a row needs to be returned
                int rowAddedToDb;

                // Counts if there are matching primary key values. If 1 or more it wont try to add.
                int           count = 0;
                List <string> curPK = clsPopInv.GetInventoryCode();
                foreach (string code in curPK)
                {
                    if (primKey == code)
                    {
                        count++;
                    }
                }

                if (count == 0)
                {
                    rowAddedToDb = db.ExecuteNonQuery(SQLQueries.AddInventoryItem(primKey, itemDesc, cost));
                    rowAdded     = true;
                }

                return(rowAdded);
            }
            catch (Exception ex)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." +
                                    MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
            }
        }