Пример #1
0
        /// <summary>
        /// Reads the input .csv file and processes the data
        /// </summary>
        /// <param name="NewPath"> Path to desired file to input data from</param>
        public void ProcessFiles(ref DataSource DS, string NewPath = "C:\\Users\\3D Infotech.3DCA-LY520-12\\Desktop\\New folder\\Git projects\\ReloadAssist\\Reloading App\\LoadData\\")
        {
            RootPath = NewPath;
            string currCaliber, currBulletBrand, currBulletType;

            // Root directory does not exist
            if (!Directory.Exists(RootPath))
            {
                return;
            }

            string[] caliberTypes = Directory.GetDirectories(RootPath);
            // If there are no caliber folders in root directory
            if (caliberTypes.Length == 0)
            {
                return;
            }

            // Loop through the caliber files and parse the folders in each
            for (int i = 0; i < caliberTypes.Length; ++i)
            {
                string[] bulletBrands = Directory.GetDirectories(caliberTypes[i]);
                // If no files in caliber folder then go to next file
                if (bulletBrands.Length == 0)
                {
                    continue;
                }

                // Get current caliber
                currCaliber = Path.GetFileName(caliberTypes[i]);
                // Create a new caliber object for every caliber found in the files
                Caliber newCal = new Caliber(currCaliber);

                // Parse all data files in each folder
                for (int j = 0; j < bulletBrands.Length; ++j)
                {
                    string[] bulletTypes = Directory.GetFiles(bulletBrands[j]);
                    // If no Bullet data exists in this folder then continue to next folder
                    if (bulletTypes.Length == 0)
                    {
                        continue;
                    }

                    // Get current bullet brand
                    currBulletBrand = Path.GetFileName(bulletBrands[j]);
                    // Create new bullet brand object for every brand found in the files
                    BulletBrand newBulletBrand = new BulletBrand(currBulletBrand);

                    // Parse each .csv data file in the folder
                    for (int k = 0; k < bulletTypes.Length; ++k)
                    {
                        string[] info = Path.GetFileName(bulletTypes[k]).Split(separators);
                        currBulletType = info[0] + " " + info[1];
                        BulletType newBulletType = new BulletType(currBulletType);

                        // Process data in the file
                        InputBulletData(bulletTypes[k], ref newBulletType);

                        // Add bulletType object to its corresponding bullet brand object
                        newBulletBrand.AddBullet(newBulletType);
                    }

                    // Add the bullet brand object to caliber object
                    newCal.AddBulletBrand(newBulletBrand);
                }
                // Add the caliber object after filled with bullet brand objects
                DS.AddCaliber(newCal);
            }
        }