コード例 #1
0
        public bool ClearData()
        {
            bool dataCleared = false;

            ListOfOffers.Clear();
            ListOfContractors.Clear();
            ListOfRoutes.Clear();
            // If the data in all the 3 lists is 0, it means that the lists are empty
            if (ListOfOffers.Count == 0 && ListOfContractors.Count == 0 && ListOfRoutes.Count == 0)
            {
                dataCleared = true;
            }

            return(dataCleared);
        }
コード例 #2
0
        private bool ImportOffer(string filepath)
        {
            bool isOfferData = false;

            //Get all the info from the CSV file
            string[] data = File.ReadAllLines(filepath, Encoding.GetEncoding("iso-8859-1"));

            //Check if there are 8 columns for the Offers
            if (data[0].Split(';').Length == 8)
            {
                isOfferData = true;
            }

            if (isOfferData)
            {
                //Go through every row on the CSV file data after the headers (i=1)
                for (int i = 1; i < data.Length; i++)
                {
                    string row = data[i];
                    //Get every column in that row
                    string[] collumns = row.Split(';');


                    string     offerId         = collumns[0];
                    int        routeNumber     = int.Parse(collumns[1]);
                    double     price           = double.Parse(collumns[2]);
                    string     contractorEmail = collumns[5];
                    Contractor contractor      = ListOfContractors[contractorEmail];
                    int        priority        = 10;
                    if (collumns[7] != "")
                    {
                        priority = int.Parse(collumns[7]);
                    }

                    Offer newOffer = new Offer(offerId, ListOfRoutes[routeNumber], price, contractor, priority);
                    ListOfOffers.Add(newOffer);
                    ListOfRoutes[routeNumber].AddToList(newOffer);
                }
            }

            if (ListOfOffers.Count <= 0)
            {
                isOfferData = false;
            }

            return(isOfferData);
        }