Exemple #1
0
        /// <summary>
        /// Checks if the Primary key letter(s) already exists in the inventory database.
        /// If so, the user will be promt if they want to overwrite the current data or not.
        /// If not, it will write it to a new row
        /// </summary>
        /// <param name="primKey"></param>
        /// <returns></returns>
        public Boolean SaveButtonCheck(string primKey)
        {
            clsUpdateInventory clsPopInv = new clsUpdateInventory();

            // Checks if primary key matches an existing primary key
            Boolean PKexists = false;
            // Gets current list of primary keys that already exist
            List <string> curPK = clsPopInv.GetInventoryCode();

            foreach (string code in curPK)
            {
                if (primKey == code)
                {
                    PKexists = true;
                }
            }
            return(PKexists);
        }
Exemple #2
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);
            }
        }