示例#1
0
    private string ListMySwaps(string Filter)
    {
        //this function lists swaps in the list box
        //it takes one parameter which is a filter
        //it returns a string indicating how many swaps were found
        //
        //var to store the SwapNo (unique identifier)
        Int32 SwapNo;
        //var to stor the swap title
        string Title;
        //create a connection to the database table applying the filter
        clsDataConnection MySwaps = new clsDataConnection("select * from swap where title like('" + Filter + "%') order by title");
        //var to store the number of swaps found
        Int32 SwapCount;

        //get the number of swaps found
        SwapCount = MySwaps.Count;
        //clear the list box
        lstSwaps.Items.Clear();
        Int32 Index = 0;

        //loop through each swap
        while (Index < SwapCount)
        {
            //get the SwapNo from the database
            SwapNo = Convert.ToInt32(MySwaps.DataTable.Rows[Index]["SwapNo"]);
            //get the Title of the swap from the database
            Title = Convert.ToString(MySwaps.DataTable.Rows[Index]["Title"]);
            //add the title to the list
            lstSwaps.Items.Add(Title);
            //set the value of the item in the list to the SwapNo
            lstSwaps.Items[Index].Value = SwapNo.ToString();
            Index++;
        }
        //if records were found
        if (MySwaps.Count > 0)
        {
            //return how many records were found
            return(MySwaps.Count + " record(s) found");
        }
        else
        {
            //return no records found
            return("No records found");
        }
    }
示例#2
0
    private void DisplaySwaps()
    {
        //this sub displays the swaps in the swaps list box
        //
        //open a connection to the database
        clsDataConnection MySwaps = new clsDataConnection("select * from swap order by title");
        //var to store the count of swaps
        Int32 SwapCount;
        //var for the loop
        Int32 Index = 0;
        //var for the swap title
        string Title;
        //var for the unique identifier of the swap
        Int32 SwapNo;
        //var to store the number of offers on a swap
        Int32 OfferCount;

        //get the number of swaps
        SwapCount = MySwaps.Count;
        //loop through each swap
        while (Index < SwapCount)
        {
            //get the swap number for this swap
            SwapNo = (Int32)MySwaps.DataTable.Rows[Index]["SwapNo"];
            //get the title for this swap
            Title = (string)MySwaps.DataTable.Rows[Index]["Title"];
            //get the number of offers on this swap
            OfferCount = GetOfferCount(SwapNo);
            //if there are no offers
            if (OfferCount == 0)
            {
                //then just add the title
                lstSwaps.Items.Add(Title);
            }
            else
            {
                //else add the title with the number of offers
                lstSwaps.Items.Add(Title + " " + OfferCount + " offer(s)");
                //End If
            }
            //set the value property for this entry in the list box
            lstSwaps.Items[Index].Value = SwapNo.ToString();
            Index++;
        }
    }