예제 #1
0
        public inventoryItem getSingleItemById(int itemId)
        {
            inventoryItem requestedItem = new inventoryItem();

            try
            {
                //Attempt to populate an instance of the "inventoryItem" class with the information requested from
                //the database.
                dbQuery   dbConnect = new dbQuery();
                DataTable dbRequest = dbConnect.requestInventoryItem(itemId);

                requestedItem.Item_Id        = Int32.Parse((dbRequest.Rows[0][0]).ToString());
                requestedItem.Item_Name      = (dbRequest.Rows[0][1]).ToString();
                requestedItem.Item_Price     = decimal.Parse((dbRequest.Rows[0][2]).ToString());
                requestedItem.Standard_Offer = Int32.Parse((dbRequest.Rows[0][3]).ToString());
                requestedItem.Loyalty_Offer  = Int32.Parse((dbRequest.Rows[0][4]).ToString());
                requestedItem.Item_Stock     = Int32.Parse((dbRequest.Rows[0][5]).ToString());
            }
            catch
            {
                //If "inventoryItem" is not properly populated, return a 0 as item Id
                //(read as an error by the PresentationLayer).
                requestedItem.Item_Id = 0;
            }

            return(requestedItem);
        }
예제 #2
0
        public void sendLoyaltyToUpdate(int id, int loyaltyNo)
        {
            //Send altered LoyaltyCard information to database.
            dbQuery updateDB = new dbQuery();

            updateDB.updateItemLoyaltyOffer(id, loyaltyNo);
        }
예제 #3
0
        public void sendPriceControlToUpdate(int id, string validatedPriceData, int offerNo)
        {
            //Send altered PriceControl form to database to update information.
            decimal price = decimal.Parse(validatedPriceData);

            dbQuery updateDB = new dbQuery();

            updateDB.updateItemPrice(id, price);
            updateDB.updateItemStandardOffer(id, offerNo);
        }
예제 #4
0
        public ListBox loadInventoryData(int formType)
        {
            ListBox   toFill    = new ListBox();
            dbQuery   dbConnect = new dbQuery();
            DataTable dbItems   = dbConnect.allInventoryItems();
            string    sp        = "   -   "; //Uniform spacing between "columns" in listbox.
            string    addItem;

            //Load class with written names for offer types (instead of Id's).
            StandardAndLoyaltyOffers offers = new StandardAndLoyaltyOffers();

            //"formType" refers to the form which called the function;
            //0 is PriceControl,
            //1 is StockMonitor
            //2 is LoyaltyCard.
            if (formType == 0)
            {
                toFill.Items.Add("Item Id" + sp + "Item Name" + sp + "Price" + sp + "Standard Offer");

                //Populate requested listbox with formatted data.
                foreach (DataRow row in dbItems.Rows)
                {
                    addItem = row[0] + sp + row[1] + sp + "£" + row[2] + sp + offers.getOfferName(Int32.Parse(row[3].ToString()));
                    toFill.Items.Add(addItem);
                }
            }
            else if (formType == 1)
            {
                toFill.Items.Add("Item Id" + sp + "Item Name" + sp + "Stock");

                //Populate requested listbox with formatted data.
                foreach (DataRow row in dbItems.Rows)
                {
                    addItem = row[0] + sp + row[1] + sp + row[5];
                    toFill.Items.Add(addItem);
                }
            }
            else if (formType == 2)
            {
                toFill.Items.Add("Item Id" + sp + "Item Name" + sp + "Loyalty Offer");

                //Populate requested listbox with formatted data.
                foreach (DataRow row in dbItems.Rows)
                {
                    addItem = row[0] + sp + row[1] + sp + offers.getLoyaltyName(Int32.Parse(row[4].ToString()));
                    toFill.Items.Add(addItem);
                }
            }

            //Return the requested data.
            return(toFill);
        }
예제 #5
0
        public int inventoryItemCount()
        {
            //Method to loop through each item in the database, to count how many items there are.
            int       itemCounter = 0;
            dbQuery   dbConnect   = new dbQuery();
            DataTable dbItems     = dbConnect.allInventoryItems();

            foreach (DataRow row in dbItems.Rows)
            {
                itemCounter++;
            }

            return(itemCounter);
        }
예제 #6
0
        public performanceReport GenerateReport()
        {
            //Report to be filled.
            performanceReport report = new performanceReport();

            //Fill a local variable with each of the sales records to be processed.
            dbQuery   accessDB = new dbQuery();
            DataTable allSales = accessDB.allAccountingRecords();

            //Local Variables for working out the values to be inserted into the
            //report.
            decimal totalEarnings  = 0;
            int     totalSales     = 0;
            int     totalCustomers = 0;

            DateTime saleDate;

            decimal thisYearEarnings  = 0;
            decimal thisYearSales     = 0;
            decimal thisYearCustomers = 0;

            decimal priorYearEarnings  = 0;
            decimal priorYearSales     = 0;
            decimal priorYearCustomers = 0;

            //Go through each record of the datatable.
            //Row[0] is Id.
            //Row[1] is date.
            //Row[2] is spend (earnings).
            //Row[3] is total individual items in purchase.
            foreach (DataRow Row in allSales.Rows)
            {
                totalEarnings += decimal.Parse(Row[2].ToString());
                totalSales    += Int32.Parse(Row[3].ToString());
                totalCustomers++;

                //Get date associated with current row.
                saleDate = DateTime.Parse(Row[1].ToString());

                //If saleDate is within 1 year of current date.
                if (saleDate < systemDate && saleDate > systemDate.AddYears(-1))
                {
                    thisYearEarnings += decimal.Parse(Row[2].ToString());
                    thisYearSales    += Int32.Parse(Row[3].ToString());
                    thisYearCustomers++;
                }
                //If saleDate is within 2 years of current date, but not within 1 year.
                else if (saleDate < systemDate.AddYears(-1) && saleDate > systemDate.AddYears(-2))
                {
                    priorYearEarnings += decimal.Parse(Row[2].ToString());
                    priorYearSales    += Int32.Parse(Row[3].ToString());
                    priorYearCustomers++;
                }
            }

            //Append all of the calculated values to report.
            report.Total_Earnings       = totalEarnings;
            report.Total_Items_Sold     = totalSales;
            report.Total_Customers      = totalCustomers;
            report.Past_Year_Earnings   = thisYearEarnings;
            report.Past_Year_Items_Sold = decimal.ToInt32(thisYearSales);
            report.Past_Year_Customers  = decimal.ToInt32(thisYearCustomers);

            //Calculate the percentage differences between this year and last,
            //then append them to the report.
            decimal percentageEarnings  = thisYearEarnings / priorYearEarnings * 100;
            decimal percentageSales     = thisYearSales / priorYearSales * 100;
            decimal percantageCustomers = thisYearCustomers / priorYearCustomers * 100;

            report.Percentage_Of_Prior_Year_Earnings   = percentageEarnings;
            report.Percentage_Of_Prior_Year_Items_Sold = percentageSales;
            report.Percentage_Of_Prior_Year_Customers  = percantageCustomers;

            //Return the filled out report class.
            return(report);
        }