コード例 #1
0
        public void LoadOrders()
        {
            try
            {
                int             ordercount = 0;                // the number of orders to display
                List <string>[] Managerdata;                   // the orders that will be displayed
                ArrayList       ListBoxInfo = new ArrayList(); // Array list where formatted text will be stored

                // connect to DB if it is not connected
                if (!nsadb.Connected())
                {
                    nsadb.OpenConnection();
                }

                //request the Records to display on the manager orders list
                ordercount = nsadb.ManagerOrdersData(out Managerdata);

                // Clear any existing data in the list box
                Orders_Listbox.DataSource = null;
                Orders_Listbox.Items.Clear();

                // If there is no data in the database skip attempting to load the List
                // It will cause an error.
                if (ordercount == 0)
                {
                    return;
                }

                //loop over the records and format them in the Array List
                for (int index = 0; index < ordercount; index++)
                {
                    if (Managerdata[2][index] == "0")
                    {
                        ListBoxInfo.Add(new BoxFormat("#" + Managerdata[0][index] + " - " + Managerdata[1][index], Managerdata[0][index]));
                    }
                    else
                    {
                        ListBoxInfo.Add(new BoxFormat("#" + Managerdata[0][index] + " - " + Managerdata[1][index] + " - Refunded", Managerdata[0][index]));
                    }
                }

                // Insert Array List into the List Box
                Orders_Listbox.DataSource = ListBoxInfo;

                // Define which information is actually displayed by the listbox and returned
                Orders_Listbox.DisplayMember = "displayText";
                Orders_Listbox.ValueMember   = "databaseID";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error loading Orders List", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        } // LoadOrders