Example #1
0
        private void cmdAdd_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
            {
                string FilePath = openFileDialog1.FileName;
                string FileName = Path.GetFileName(FilePath);

                #region Get Extension and FileType

                string        extension   = Path.GetExtension(FilePath);
                List <string> field_names = new List <string>();

                switch (extension)
                {
                case ".csv":
                    //FileType = SweepstakesOS.FileType.CSV;
                    break;

                case ".xls":
                case ".xlsx":
                    //FileType = SweepstakesOS.FileType.CSV;
                    FilePath = FileOperations.SaveAsCSV(FilePath, FileName);
                    break;

                default:
                    break;
                }

                #endregion

                listBox1.Items.Add(new FileStructure(FilePath));
                GetSharedHeaders();
            }
        }
Example #2
0
        private void cmdAddFolder_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            //string FilePath = @"C:\Users\Shawn\Documents\5) Oaktree\2) Sweepstakes\Projects\2) 2017\3) Gene Excel Union";// folderBrowserDialog1.SelectedPath;
            bool convert_excel = chkConvert.Checked;

            //if(folderBrowserDialog1.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
            //{
            //string FileName = Path.GetFileName(FilePath);

            #region Convert Excel Files without Corresponding CSV

            if (convert_excel)
            {
                List <string> csv_files = Directory.GetFiles(FilePath, "*.csv", SearchOption.TopDirectoryOnly)
                                          .ToList();
                csv_files.ForEach(s => Path.GetFileNameWithoutExtension(s));
                List <string> excel_files = Directory.GetFiles(FilePath, "*.xlsx", SearchOption.TopDirectoryOnly)
                                            .ToList();

                for (int i = 0; i < excel_files.Count; i++)
                {
                    excel_files[i] = Path.GetFileNameWithoutExtension(excel_files[i]);
                }

                excel_files = excel_files.Where(s => !csv_files.Contains(s)).ToList();

                for (int i = 0; i < excel_files.Count; i++)
                {
                    excel_files[i] = FilePath + "\\" + excel_files[i] + ".xlsx";
                }

                foreach (string s in excel_files)
                {
                    FileOperations.SaveAsCSV(s, Path.GetFileNameWithoutExtension(s));
                }
            }
            #endregion

            List <string> files = Directory.GetFiles(FilePath, "*.csv", SearchOption.TopDirectoryOnly)
                                  .ToList();

            #region Get Extension and FileType

            FileStructure file_struct = null;
            foreach (string file in files)
            {
                string extension = Path.GetExtension(file);
                string filename  = Path.GetFileNameWithoutExtension(file);
                string csvfile   = file;
                //If not CSV, convert
                if (extension != ".csv")
                {
                    csvfile = FileOperations.SaveAsCSV(file, filename);
                }

                List <string> field_names = new List <string>();
                file_struct = new FileStructure(csvfile);

                //switch(extension)
                //{
                //    case ".csv":
                //        //FileType = SweepstakesOS.FileType.CSV;
                //        break;
                //    case ".xls":
                //    case ".xlsx":
                //        //FileType = SweepstakesOS.FileType.CSV;
                //        //FilePath = FileOperations.SaveAsCSV(FilePath, file);
                //        break;
                //    default:
                //        break;
                //}
                listBox1.Items.Add(file_struct);
            }

            #endregion

            //}
            GetSharedHeaders();
            this.Cursor = Cursors.Default;
        }