/// <summary>
        /// Calls a method in OrderRepository to retrieve orders and their total/running total for a customer,
        /// whose information is passed by the user in EmployeeView.
        /// </summary>
        /// <param name="ev">The Employee View form that this form was initialized by.</param>
        /// <param name="o">The search conditions needed to find the correct customer(s).</param>
        public ReceiptSearchResults(EmployeeView ev, SearchConditions o)
        {
            this.ev = ev;

            OrderRepository or = new OrderRepository();
            List <Order>    lo = or.RetrieveOrders(o);

            InitializeComponent();
            foreach (Order order in lo)
            {
                string[] s = { order.CustomerID.ToString(), order.OrderID.ToString(), order.First, order.Last, order.Email, order.RunningTotal.ToString("$0.00"), order.Total.ToString("$.00") };
                this.uxResults.Rows.Add(s);
            }
        }
Exemple #2
0
        /// <summary>
        /// Handles a click event on the Find Receipt Button, Takes given input and creates a new SearchConditions;
        /// then opens a window that displays the matching customer's orders and information.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnFindReceipt_Click(object sender, EventArgs e)
        {
            string           first;
            string           last;
            string           email;
            int              customerId;
            SearchConditions c;

            if (uxCustomerId.Text == "")
            {
                customerId = -1;
            }
            else
            {
                customerId = Convert.ToInt32(uxCustomerId.Text);
            }
            if (uxEmail.Text == "")
            {
                email = "*";
            }
            else
            {
                email = uxEmail.Text;
            }

            if (uxLastName.Text == "")
            {
                last = "*";
            }
            else
            {
                last = uxLastName.Text;
            }

            if (uxFirstName.Text == "")
            {
                first = "*";
            }
            else
            {
                first = uxFirstName.Text;
            }
            c            = new SearchConditions(customerId, first, last, email);
            searchWindow = new ReceiptSearchResults(this, c);
            searchWindow.ShowDialog();
        }
Exemple #3
0
        /// <summary>
        /// When provided a SearchConditions object, the method may query the database for any order with the given search conditions.
        /// </summary>
        /// <param name="sc">Search Condition Object which holds the conditions from the user for searching orders.</param>
        /// <returns>A list of orders that match the criteria given by the Search Conditions object</returns>
        public List <Order> RetrieveOrders(SearchConditions sc)
        {
            string connectionString = "Server=mssql.cs.ksu.edu;Database=cis560_team21; Integrated Security=true";

            try
            {
                using (var connection = new SqlConnection(connectionString))
                {
                    using (var command = new SqlCommand("GameStore.RetrieveCustomerOrders", connection))
                    {
                        command.CommandType = CommandType.StoredProcedure;



                        command.Parameters.AddWithValue("CustomerId", sc.CustomerId);
                        command.Parameters.AddWithValue("First", sc.First);
                        command.Parameters.AddWithValue("Last", sc.Last);
                        command.Parameters.AddWithValue("Email", sc.Email);
                        connection.Open();

                        var reader = command.ExecuteReader();

                        var orderList = new List <Order>();

                        while (reader.Read())
                        {
                            orderList.Add(new Order(
                                              reader.GetInt32(reader.GetOrdinal("CustomerId")),
                                              reader.GetInt32(reader.GetOrdinal("OrderId")),
                                              reader.GetString(reader.GetOrdinal("FirstName")),
                                              reader.GetString(reader.GetOrdinal("LastName")),
                                              reader.GetString(reader.GetOrdinal("Email")),
                                              Convert.ToDouble(reader.GetDecimal(reader.GetOrdinal("RunningTotal"))),
                                              Convert.ToDouble(reader.GetDecimal(reader.GetOrdinal("OrderTotal")))));
                        }

                        return(orderList);
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Unable to connect to database.");
                return(new List <Order>());
            }
        }
Exemple #4
0
        /// <summary>
        /// Constructor for SearchResults and retireves all the games related to the search parameters in g
        /// </summary>
        /// <param name="sa">The Store application that created this form.</param>
        /// <param name="g">A game object with all the parameters given to find games</param>
        public SearchResults(GameApplication sa, SearchConditions g)
        {
            this.sa = sa;


            GameRepository gr = new GameRepository();
            List <Game>    lg = gr.RetrieveGames(g);

            InitializeComponent();
            foreach (Game ga in lg)
            {
                string[] s = { ga.Title, ga.Genre, ga.Price.ToString(), ga.IsUsed, ga.StoreId.ToString(), ga.GameId.ToString(), ga.Quantity.ToString(), ga.Platform.ToString() };
                bool     allAreInReceipt = sa.RemoveFromSearch(s);

                if (!allAreInReceipt)
                {
                    this.uxResults.Rows.Add(s);
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Connects to the database and querys using the given input paramaters then opens a window to display the query results
        /// </summary>
        private void btnFind_Click(object sender, EventArgs e)
        {
            string           title;
            string           genre;
            string           platform;
            double           minPrice;
            double           maxPrice;
            int              isUsed;
            int              storeId;
            SearchConditions sc;

            if (uxStoreId.Text == "")
            {
                MessageBox.Show("Please enter a Store Id.");
            }
            else
            {
                storeId = Convert.ToInt32(uxStoreId.Text);

                if (uxTitle.Text != "")
                {
                    title = uxTitle.Text;
                }
                else
                {
                    title = "*";
                }


                if (uxGenre.Text == "")
                {
                    genre = "*";
                }
                else
                {
                    genre = uxGenre.Text;
                }

                if (uxPlatform.Text == "")
                {
                    platform = "*";
                }
                else
                {
                    platform = uxPlatform.Text;
                }

                if (uxPriceRange.SelectedIndex == 0)
                {
                    minPrice = -1;
                    maxPrice = -1;
                }
                else if (uxPriceRange.SelectedIndex == 1)
                {
                    minPrice = 0;
                    maxPrice = 9.99;
                }
                else if (uxPriceRange.SelectedIndex == 2)
                {
                    minPrice = 10;
                    maxPrice = 19.99;
                }
                else if (uxPriceRange.SelectedIndex == 3)
                {
                    minPrice = 20;
                    maxPrice = 29.99;
                }
                else if (uxPriceRange.SelectedIndex == 4)
                {
                    minPrice = 30;
                    maxPrice = 39.99;
                }
                else if (uxPriceRange.SelectedIndex == 5)
                {
                    minPrice = 40;
                    maxPrice = 49.99;
                }
                else if (uxPriceRange.SelectedIndex == 6)
                {
                    minPrice = 50;
                    maxPrice = 59.99;
                }
                else if (uxPriceRange.SelectedIndex == 7)
                {
                    minPrice = 60;
                    maxPrice = 69.99;
                }
                else if (uxPriceRange.SelectedIndex == 8)
                {
                    minPrice = 70;
                    maxPrice = 79.99;
                }
                else
                {
                    minPrice = 80;
                    maxPrice = -1;
                }

                if (uxCondition.SelectedIndex == 0)
                {
                    isUsed = -1;
                }
                else if (uxCondition.SelectedIndex == 1)
                {
                    isUsed = 0;
                }
                else
                {
                    isUsed = 1;
                }

                btnFind.Enabled = false;
                sc           = new SearchConditions(title, genre, platform, minPrice, maxPrice, isUsed, storeId);
                searchWindow = new SearchResults(this, sc);
                searchWindow.ShowDialog();
                btnFind.Enabled = true;
            }
        }
        /// <summary>
        /// When provided a SearchConditions object the method may query the database for any game with the given search conditions.
        /// </summary>
        /// <param name="sc">Search Condition Object which holds the conditions from the user for search games.</param>
        /// <returns>A list of games that match the criteria given by the Search Conditions object</returns>
        public List <Game> RetrieveGames(SearchConditions sc)
        {
            string connectionString = "Server=mssql.cs.ksu.edu;Database=cis560_team21; Integrated Security=true";
            string condition        = "";

            try
            {
                using (var connection = new SqlConnection(connectionString))
                {
                    using (var command = new SqlCommand("GameStore.RetrieveGames", connection))
                    {
                        command.CommandType = CommandType.StoredProcedure;


                        if (sc.IsUsed == 0)
                        {
                            condition = "New";
                        }
                        else if (sc.IsUsed == 1)
                        {
                            condition = "Used";
                        }
                        else
                        {
                            condition = "*";
                        }


                        command.Parameters.AddWithValue("Title", sc.Title);
                        command.Parameters.AddWithValue("Genre", sc.Genre);
                        command.Parameters.AddWithValue("MinPrice", sc.MinPrice);
                        command.Parameters.AddWithValue("MaxPrice", sc.MaxPrice);
                        command.Parameters.AddWithValue("StoreId", sc.StoreId);
                        command.Parameters.AddWithValue("IsUsed", condition);
                        command.Parameters.AddWithValue("Platform", sc.Platform);
                        connection.Open();

                        var reader = command.ExecuteReader();

                        var gameList = new List <Game>();

                        while (reader.Read())
                        {
                            if (reader.GetBoolean(reader.GetOrdinal("Condition")) == true)
                            {
                                condition = "used";
                            }
                            else
                            {
                                condition = "new";
                            }

                            gameList.Add(new Game(
                                             reader.GetString(reader.GetOrdinal("Title")),
                                             reader.GetString(reader.GetOrdinal("GenreName")),
                                             reader.GetString(reader.GetOrdinal("PlatformName")),
                                             reader.GetDecimal(reader.GetOrdinal("UnitPrice")).ToString(),
                                             reader.GetInt32(reader.GetOrdinal("Quantity")),
                                             condition,
                                             reader.GetInt32(reader.GetOrdinal("StoreId")),
                                             reader.GetInt32(reader.GetOrdinal("GameStoreInfoId"))));
                        }

                        return(gameList);
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Unable to connect to database.");
                return(new List <Game>());
            }
        }