Hello, I'm currently writing a program which will handle bookings for a campsite.
Im having some trouble with the search function and i am looking for some help.

There is a text file with the orders which is copied into an array when the program starts. The text file is layed out as follows;

will mccreedy -Name
willy -Nickname
12 saint street -Address
01/02/2003 -booking date (todays)
13:00 -booking time (now)
caravan -type of booking Combo Box
need to bring pet -special requirements
booked -status of booking Combo Box

Can anyone help me with a search function for this array which will search on any criteria above will display the data from that order in individual text boxes .

Many thanks
Samamam

Recommended Answers

All 3 Replies

You could create a class to store each object, place them in a generic list and use the List<T>.Find() method to search for them.

Alternatively, if you are on .net 3.5 you can use LINQ to Objects to query an array.

Ive got a class Order which ive used on a seperate form for adding a new order to the List which is;

class Order
        {
            public string Name { get; set; }
            public string NickName { get; set; }
            public string Address { get; set; }
            public string OrderDate { get; set; }
            public string OrderTime { get; set; }
            public string MealType { get; set; }
            public string DeliveryRequirements { get; set; }
            public string OrderStatus { get; set; }


            public Order(string Name, string NickName, string Address, string OrderDate, string OrderTime, string MealType, string DeliveryRequirements, string OrderStatus)
            {
                this.Name = Name;
                this.NickName = NickName;
                this.Address = Address;
                this.OrderDate = OrderDate;
                this.OrderTime = OrderTime;
                this.MealType = MealType;
                this.DeliveryRequirements = DeliveryRequirements;
                this.OrderStatus = OrderStatus;
            }

            public Order() // empty contructor to create Order from textboxes etc
            {
            }

            public Order(string line) // constructor to create Order from line in file
            {
                // splits out fields from a line in file
                string[] fields = line.Split(',');
                Name = fields[0];
                NickName = fields[1];
                Address = fields[2];
                OrderDate = fields[3];
                OrderTime = fields[4];
                MealType = fields[5];
                DeliveryRequirements = fields[6];
                OrderStatus = fields[7];
            }

            public override string ToString()
            {
                // construct line from fields
                string s =
                Name + "," +
                NickName + "," +
                Address + "," +
                OrderDate + "," +
                OrderTime + "," +
                MealType + "," +
                DeliveryRequirements + "," +
                OrderStatus;
                return s;

            }
        }

can this be used at all in the search function with a foreach loop to search through the list to find a certain criteria then display the rest of the order associated with that criteria or will the program need to know how many fields make up an order so it can display the fields above and below it from the List e.g

name
nickname
address
order date
order time
meal type
order status

if the criteria is order date, tthe 3 fields abovr and the 3 fields below it will need to be diplayed in their respective text boxes?

or will it know which data to display because of the Class?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.