private void Find_loc_btn_Click(object sender, RoutedEventArgs e) //location find
        {
            string[] found_line = CsvIO.findCsvLine(loc_srch_TextBox.Text, 1, "locations.csv");

            if (found_line[0] == "Error 1! Record Not Found. Please try again.")
            {
                MessageBox.Show("Input existing location.", "Instructions", MessageBoxButton.OK, MessageBoxImage.Information);
                loc_srch_TextBox.Text = String.Empty;

            }
            else
            {
                visit3.Visit_location_name = found_line[1];

                MessageBoxResult result2 = MessageBox.Show("Is that the correct location? \n" + visit3.Visit_location_name, "Location Found", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (result2 == MessageBoxResult.Yes)
                {
                    save_btn.IsEnabled = true;
                }
                else
                {
                    MessageBox.Show("Try Again.", "Instructions", MessageBoxButton.OK, MessageBoxImage.Information);
                    loc_srch_TextBox.Text = String.Empty;
                }
            }
        }
Ejemplo n.º 2
0
 private readonly string _path = string.Empty; //ConfigurationManager.AppSettings["GroceryDatabase"]
 public ProductRepository()
 {
     foreach (string line in CsvIO.ReadCSVString(_path).Skip(1))
     {
         string[] values = line.Split(',');
         Items.Add(new Product(values[0], Convert.ToInt32(values[1]), Convert.ToDouble(values[2])));
     }
     ;
 }
Ejemplo n.º 3
0
        private void Import_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog
            {
                InitialDirectory = Directory.GetCurrentDirectory(),
                Filter           = "CSV File (*.csv)|*.csv",
                ReadOnlyChecked  = true
            };

            if (openFileDialog.ShowDialog() != true)
            {
                return;
            }
            var file = openFileDialog.FileName;
            List <IShellItem> csvShelltems = CsvIO.ImportCSVFile(file);

            if (csvShelltems.Count == 0)
            {
                LogAggregator.Instance.ShowIfNotEmpty();
                return;
            }

            if (App.ShellItems != null)
            {
                App.ShellItems.Clear();
            }
            if (App.nodeCollection.nodeList != null)
            {
                App.nodeCollection.nodeList.Clear();
            }

            App.ShellItems = csvShelltems;
            List <IEvent> events = EventParser.GetEvents(App.ShellItems);

            App.nodeCollection.ClearAllFilters();
            App.nodeCollection.nodeList.AddRange(NodeParser.GetNodes(events));

            if (Home.timelinePage == null)
            {
                Home.timelinePage = new TimelinePage();
                App.NavigationService.Navigate(Home.timelinePage);
            }
            else
            {
                Home.timelinePage.RebuildTimeline();
                string timelinePageKey = "timelinepage";
                if (App.pages.ContainsKey(timelinePageKey))
                {
                    App.NavigationService.Navigate(App.pages[timelinePageKey]);
                }
                else
                {
                    App.NavigationService.Navigate(Home.timelinePage);
                }
            }
            LogAggregator.Instance.ShowIfNotEmpty();
        }
Ejemplo n.º 4
0
 private void OkLoc_btn_Click(object sender, RoutedEventArgs e)
 {
     if (string.IsNullOrWhiteSpace(location_input_textbox.Text) || string.IsNullOrWhiteSpace(location_input_textbox.Text))
     {
         MessageBox.Show("Error! Empty field detected.", "Instructions", MessageBoxButton.OK, MessageBoxImage.Information);
     }
     else
     {
         Location l1 = new Location();
         l1.Location_name = location_input_textbox.Text;
         MessageBox.Show("Location: " + l1.Location_name + " added successfully!");
         CsvIO.importCSV("locations.csv", "id,locationName", l1.Location_name);
     }
 }
Ejemplo n.º 5
0
        static void RunReadExamples()
        {
            Console.WriteLine("RunReadExamples()");


            IEnumerable <Company> companies = Enumerable.Empty <Company>();

            ConsoleKeyInfo response = new ConsoleKeyInfo();

            do
            {
                Console.WriteLine();
                Console.WriteLine("[1] = CsvIO.ReadCsvFile1");
                Console.WriteLine("[2] = ExcelIO.ReadExcelFile1");
                Console.WriteLine("[e] = Exit");

                Console.Write("\r\nEnter choice: ");
                response = Console.ReadKey();
                Console.WriteLine("\r\n");

                Stopwatch sw = null;

                switch (response.Key)
                {
                case ConsoleKey.D1:
                    sw        = Stopwatch.StartNew();
                    companies = CsvIO.ReadCsvFile1();
                    break;

                case ConsoleKey.D2:
                    sw        = Stopwatch.StartNew();
                    companies = ExcelIO.ReadExcelFile1();
                    break;

                case ConsoleKey.E:
                case ConsoleKey.Escape:
                    break;

                default:
                    Console.WriteLine("Invalid choice.");
                    break;
                }

                if (sw != null && sw.IsRunning)
                {
                    sw.Stop();
                    Common.WriteTime(String.Format("\r\nRead file returning {0} companies total seconds: ", companies.Count()), sw.Elapsed);
                }
            } while (!(response.Key == ConsoleKey.E || response.Key == ConsoleKey.Escape));
        }
Ejemplo n.º 6
0
 /// <summary>
 /// This checks when the download button is hit, whether the HTML and/or the CSV checkbox is checked or not and calls the creation of HtmlOutput.
 /// </summary>
 private void DownloadClick(object sender, RoutedEventArgs e)
 {
     if (htmlCheckBox.IsChecked ?? false)
     {
         SaveFileDialog saveFileDialog1 = new SaveFileDialog();
         saveFileDialog1.DefaultExt   = ".html";
         saveFileDialog1.Filter       = "Html File (*.html)| *.html";
         saveFileDialog1.AddExtension = true;
         saveFileDialog1.ShowDialog();
         string name = saveFileDialog1.FileName;
         if (name != string.Empty)
         {
             List <Node.Node> visibleNodes = App.nodeCollection.nodeList
                                             .Where(node => node.Visibility == Visibility.Visible).ToList();
             HtmlIO.OutputHtmlFile(visibleNodes, name);
         }
     }
     if (csvCheckBox.IsChecked ?? false)
     {
         SaveFileDialog saveFileDialog2 = new SaveFileDialog();
         saveFileDialog2.DefaultExt   = ".csv";
         saveFileDialog2.Filter       = "CSV File (*.csv)| *.csv";
         saveFileDialog2.AddExtension = true;
         saveFileDialog2.ShowDialog();
         string name2 = saveFileDialog2.FileName;
         if (name2 != string.Empty)
         {
             var file = new FileInfo(name2);
             if (file.Exists)
             {
                 try // Check if the file is locked
                 {
                     using (FileStream stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.None))
                     {
                         stream.Close();
                     }
                 }
                 catch (IOException ex)
                 {
                     System.Windows.MessageBox.Show("The file: \"" + name2 + "\" is being used by another process.\n" +
                                                    "Select a different file name or close the process to save the CSV.", "Cannot save file", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                     logger.Info(ex, "The file: \"" + name2 + "\" is being used by another process.\n" + ex.ToString());
                     return;
                 }
             }
             CsvIO.OutputCSVFile(App.ShellItems, name2);
         }
     }
 }
        private void OK_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(FullName_TxtBox.Text) || string.IsNullOrWhiteSpace(PhoneNumber_TxtBox.Text))
            {
                MessageBox.Show("Error! Empty field detected.", "Instructions", MessageBoxButton.OK, MessageBoxImage.Information);
            }

            else if (FullName_TxtBox.Text.Any(char.IsDigit))
            {
                MessageBox.Show("Error! Name should contain only letters.", "Instructions", MessageBoxButton.OK, MessageBoxImage.Information);
            }

            else if (PhoneNumber_TxtBox.Text.Length != 10 || PhoneNumber_TxtBox.Text.Any(char.IsLetter))
            {
                MessageBox.Show("Please input a correct phone number, whitout coutry code.", "Instructions", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                User User1 = new User();
                User1.Name         = FullName_TxtBox.Text;
                User1.Phone_number = PhoneNumber_TxtBox.Text;
                string header = "Id,UserName,UserPhone";
                string toCsv  = User1.Name + "," + User1.Phone_number;
                CsvIO.importCSV("users.csv", header, toCsv);

                MessageBoxResult result = MessageBox.Show("Individual: " + User1.Name + ", with phone number: " + User1.Phone_number + ", added successful! \n Do you want to add another user?", "Dialog", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (result == MessageBoxResult.Yes)
                {
                    FullName_TxtBox.Text    = String.Empty;
                    PhoneNumber_TxtBox.Text = String.Empty;
                    User1.Name         = String.Empty;
                    User1.Phone_number = String.Empty;
                }
                else
                {
                    Close();
                }
            }
        }
Ejemplo n.º 8
0
        public void OutputCSVFileTest()
        {
            List <IShellItem>           shellItems          = new List <IShellItem>();
            Dictionary <string, string> shellItemProperties = new Dictionary <string, string>();

            shellItemProperties.Add("Size", "0");
            shellItemProperties.Add("Type", "31");
            shellItemProperties.Add("TypeName", "Some Type Name");
            shellItemProperties.Add("Name", "Some Name");
            shellItemProperties.Add("ModifiedDate", "1/1/0001 12:00:00 AM");
            shellItemProperties.Add("AccessedDate", "1/1/0001 12:00:00 AM");
            shellItemProperties.Add("CreationDate", "1/1/0001 12:00:00 AM");
            CsvParsedShellItem ShellItem = new CsvParsedShellItem(shellItemProperties);

            shellItems.Add(ShellItem);

            if (File.Exists("raw.csv"))
            {
                File.Delete("raw.csv");
            }
            CsvIO.OutputCSVFile(shellItems, "raw.csv");
            Assert.IsTrue(File.Exists("raw.csv"));
        }
Ejemplo n.º 9
0
        public void ExportAndImportCSVWithSpecialCharactersTest()
        {
            // Export
            List <IShellItem>           shellItems          = new List <IShellItem>();
            Dictionary <string, string> shellItemProperties = new Dictionary <string, string>();

            shellItemProperties.Add("Size", "0");
            shellItemProperties.Add("Type", "31");
            shellItemProperties.Add("TypeName", "Some Type Name");
            shellItemProperties.Add("Name", "Some Name, \n \"Name\"");
            shellItemProperties.Add("ModifiedDate", "1/1/0001 12:00:00 AM");
            shellItemProperties.Add("AccessedDate", "1/1/0001 12:00:00 AM");
            shellItemProperties.Add("CreationDate", "1/1/0001 12:00:00 AM");
            CsvParsedShellItem ShellItem = new CsvParsedShellItem(shellItemProperties);

            shellItems.Add(ShellItem);

            if (File.Exists("raw.csv"))
            {
                File.Delete("raw.csv");
            }
            CsvIO.OutputCSVFile(shellItems, "raw.csv");
            Assert.IsTrue(File.Exists("raw.csv"));

            // Import
            List <IShellItem>            importedShellItems = CsvIO.ImportCSVFile("raw.csv");
            IDictionary <string, string> allProperties      = importedShellItems[0].GetAllProperties();

            Assert.IsTrue(allProperties["Size"].Equals("0"));
            Assert.IsTrue(allProperties["Type"].Equals("31"));
            Assert.IsTrue(allProperties["TypeName"].Equals("Some Type Name"));
            Assert.IsTrue(allProperties["Name"].Equals("Some Name, \n \"Name\""));
            Assert.IsTrue(allProperties["ModifiedDate"].Equals("1/1/0001 12:00:00 AM"));
            Assert.IsTrue(allProperties["AccessedDate"].Equals("1/1/0001 12:00:00 AM"));
            Assert.IsTrue(allProperties["CreationDate"].Equals("1/1/0001 12:00:00 AM"));
        }
 /// <summary>
 /// CSVにエクスポートする。
 /// </summary>
 /// <param name="targetList">出力対象データ</param>
 /// <param name="filePath">ファイルパス</param>
 public Task ExportAsync(IEnumerable <EnemyParameter> targetList, string filePath)
 {
     return(CsvIO.WriteEnemyParametersAsync(targetList, filePath));
 }
Ejemplo n.º 11
0
        //Button for Find Person 1
        private void FindUser_btn_Click(object sender, RoutedEventArgs e)
        {
            //Making a string with an error message, that would be returned from function findCsvLine if line doesnt exists
            string error = "Error 1! Record Not Found. Please try again.";

            //flow control with switch and goto. Was with ifs and else's but currently is more readable and less repeated code.
            switch (select_cmBox.SelectedIndex)
            {
            case 0:     //phone number selected
                if (phone_inp_txtBox != null && !string.IsNullOrWhiteSpace(phone_inp_txtBox.Text))
                {
                    string[] name_phone = CsvIO.findCsvLine(phone_inp_txtBox.Text, 2, "users.csv");
                    if (name_phone[0] == error)
                    {
                        goto case 4;
                    }
                    user1.User_name  = name_phone[1];
                    user1.User_phone = name_phone[2];
                    goto case 5;
                }
                else
                {
                    goto case 3;
                }

            case 1:     //name selected

                if (name_inp_txtBox != null && !string.IsNullOrWhiteSpace(name_inp_txtBox.Text))
                {
                    string[] name_phone = CsvIO.findCsvLine(name_inp_txtBox.Text, 1, "users.csv");
                    if (name_phone[0] == error)
                    {
                        goto case 4;
                    }
                    user1.User_name  = name_phone[1];
                    user1.User_phone = name_phone[2];
                    goto case 5;
                }
                else
                {
                    goto case 3;
                }

            case 3:     //input empty
                MessageBox.Show("Please input search term!", "Instructions", MessageBoxButton.OK, MessageBoxImage.Information);
                break;

            case 4:     //user not found
                MessageBox.Show("User not found in the database! Please try again!", "Instructions", MessageBoxButton.OK, MessageBoxImage.Information);
                user1.User_name  = String.Empty;
                user1.User_phone = String.Empty;
                break;

            case 5:     //final check
                MessageBoxResult result = MessageBox.Show("Is that the correct user? \n" + user1.User_name + " " + user1.User_phone, "User Found", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (result == MessageBoxResult.No)
                {
                    MessageBox.Show("Try Again.", "Instructions", MessageBoxButton.OK, MessageBoxImage.Information);
                    user1.User_name       = String.Empty;
                    user1.User_phone      = String.Empty;
                    phone_inp_txtBox.Text = String.Empty;
                    name_inp_txtBox.Text  = String.Empty;
                }

                if (result == MessageBoxResult.Yes)
                {
                    findUser_btn.IsEnabled = false;
                    save_btn.IsEnabled     = true;
                    select_cmBox.IsEnabled = false;
                }
                break;
            }
        }
Ejemplo n.º 12
0
        private void Save_btn_Click(object sender, RoutedEventArgs e)
        {
            int caseSwitch = 1;

            switch (caseSwitch)
            {
            case 1:     //check if input is valid

                if (string.IsNullOrWhiteSpace(user1.User_name) || string.IsNullOrWhiteSpace(user1.User_name))
                {
                    MessageBox.Show("Error! Idividual not selected. Try Again!", "Instructions", MessageBoxButton.OK, MessageBoxImage.Information);
                    break;
                }
                if (DatePicker.SelectedDate == null)
                {
                    MessageBox.Show("Error! Date not selected. Try Again!", "Instructions", MessageBoxButton.OK, MessageBoxImage.Information);
                    break;
                }
                if (hour_text_box.Text == "Hour" || minute_text_box.Text == "Minute" || string.IsNullOrWhiteSpace(minute_text_box.Text) || string.IsNullOrWhiteSpace(hour_text_box.Text))
                {
                    MessageBox.Show("Error! Time not selected. Try Again!", "Instructions", MessageBoxButton.OK, MessageBoxImage.Information);
                    break;
                }

                else
                {
                    goto case 2;
                }

            case 2:     //Time validation and input
                bool success1 = Int32.TryParse(hour_text_box.Text, out int hours);
                bool success2 = Int32.TryParse(minute_text_box.Text, out int minutes);

                if (success1 && success2 && hours >= 0 && hours <= 23 && minutes >= 0 && minutes <= 59)
                {
                    user1.Event_time = hours + ":" + minutes;

                    if (minutes < 10)
                    {
                        user1.Event_time = String.Empty;
                        string minutes_0 = string.Format("0{0}", minutes);
                        user1.Event_time = hours + ":" + minutes_0;
                    }
                    MessageBoxResult result_time = MessageBox.Show("Is that the correct Time? \n" + user1.Event_time, "Time Validation", MessageBoxButton.YesNo, MessageBoxImage.Question);
                    if (result_time == MessageBoxResult.Yes)
                    {
                        goto case 3;
                    }
                    else
                    {
                        user1.Event_time = String.Empty;
                        MessageBox.Show("Please input time again!", "Instructions", MessageBoxButton.OK, MessageBoxImage.Information);
                        break;
                    }
                }
                else
                {
                    MessageBox.Show("Invalid Time Input! Please Try Again! ", "Instructions", MessageBoxButton.OK, MessageBoxImage.Information);
                    break;
                }

            case 3:     //date validation and input in CSV
                string           date   = DatePicker.SelectedDate.Value.ToString("MM/dd/yyyy");
                MessageBoxResult result = MessageBox.Show("Is that the correct date? \n" + date, "Date Validation", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (result == MessageBoxResult.Yes)
                {
                    user1.Event_date = date;
                    string header = "ContactId,UserName1,UserPhone1,UserName2,UserPhone2,ContactDate,ContactTime";
                    string toCsv  = user1.User_name + "," + user1.User_phone + "," + user2.User_name + "," + user2.User_phone + "," + user1.Event_date + "," + user1.Event_time;
                    CsvIO.importCSV("contact.csv", header, toCsv);
                    MessageBox.Show("Contact saved successfuly!");

                    MessageBoxResult again = MessageBox.Show("Contact saved successfuly! \n Do you want to record another contact?", "Dialog", MessageBoxButton.YesNo, MessageBoxImage.Question);
                    if (again == MessageBoxResult.Yes)
                    {
                        user1.User_name         = String.Empty;
                        user1.User_phone        = String.Empty;
                        user2.User_name         = String.Empty;
                        user2.User_phone        = String.Empty;
                        user1.Event_date        = String.Empty;
                        user1.Event_time        = String.Empty;
                        select_cmBox.IsEnabled  = true;
                        phone_inp_txtBox.Text   = String.Empty;
                        name_inp_txtBox.Text    = String.Empty;
                        hour_text_box.Text      = String.Empty;
                        minute_text_box.Text    = String.Empty;
                        phone_inp_txtBox_2.Text = String.Empty;
                        name_inp_txtBox_2.Text  = String.Empty;
                    }
                    else
                    {
                        Close();
                    }
                }
                else
                {
                    MessageBox.Show("Please try again!", "Instructions", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                break;
            }
        }
Ejemplo n.º 13
0
        //button for user 2, same code, different variables, considered functions, but could find how to make them with objects
        private void FindUser_btn_2_Click(object sender, RoutedEventArgs e)
        {
            string error = "Error 1! Record Not Found. Please try again."; //find csv function returns the same error

            switch (select_cmBox_2.SelectedIndex)
            {
            case 0:     ///phone number
                if (phone_inp_txtBox_2 != null && !string.IsNullOrWhiteSpace(phone_inp_txtBox_2.Text))
                {
                    string[] name_phone = CsvIO.findCsvLine(phone_inp_txtBox_2.Text, 2, "users.csv");
                    if (name_phone[0] == error)     //if error is returned
                    {
                        goto case 4;
                    }
                    user2.User_name  = name_phone[1];
                    user2.User_phone = name_phone[2];
                    goto case 5;
                }
                else
                {
                    goto case 3;
                }

            case 1:     //name
                if (name_inp_txtBox_2 != null && !string.IsNullOrWhiteSpace(name_inp_txtBox_2.Text))
                {
                    string[] name_phone = CsvIO.findCsvLine(name_inp_txtBox_2.Text, 1, "users.csv");
                    if (name_phone[0] == error)
                    {
                        goto case 4;
                    }
                    user2.User_name  = name_phone[1];
                    user2.User_phone = name_phone[2];
                    goto case 5;
                }
                else
                {
                    goto case 3;
                }

            case 3:     //input empty
                MessageBox.Show("Please input search term!", "Instructions", MessageBoxButton.OK, MessageBoxImage.Information);
                break;

            case 4:     //user not found
                MessageBox.Show("User not found in the database! Please try again!", "Instructions", MessageBoxButton.OK, MessageBoxImage.Information);
                user2.User_name  = String.Empty;
                user2.User_phone = String.Empty;
                break;

            case 5:     //final check
                MessageBoxResult result = MessageBox.Show("Is that the correct user? \n" + user2.User_name + " " + user2.User_phone, "User Found", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (result == MessageBoxResult.No)
                {
                    MessageBox.Show("Try Again.", "Instructions", MessageBoxButton.OK, MessageBoxImage.Information);
                    user2.User_name         = String.Empty;
                    user2.User_phone        = String.Empty;
                    phone_inp_txtBox_2.Text = String.Empty;
                    name_inp_txtBox_2.Text  = String.Empty;
                }

                if (result == MessageBoxResult.Yes)
                {
                    findUser_btn_2.IsEnabled = false;
                    save_btn.IsEnabled       = true;
                    select_cmBox.IsEnabled   = false;
                    DatePicker.IsEnabled     = true;
                    Date_input_lbl.IsEnabled = true;
                    Time_pick_lbl.IsEnabled  = true;
                }
                break;
            }
        }
Ejemplo n.º 14
0
        static void RunWriteExamples()
        {
            Console.WriteLine("RunWriteExamples()");

            var data = Common.GetCompanies();

            ConsoleKeyInfo response = new ConsoleKeyInfo();

            bool openFiles = false;

            Console.Write("\r\nDo you wish to open each file as it is created? [y|n] ");
            response  = Console.ReadKey();
            openFiles = response.Key == ConsoleKey.Y;

            Console.WriteLine("\r\n");
            do
            {
                Console.WriteLine();
                Console.WriteLine("[1] = CsvIO.WriteCsvFile1");
                Console.WriteLine("[2] = CsvIO.WriteCsvFile2");
                Console.WriteLine("[3] = CsvIO.WriteCsvFile3");
                Console.WriteLine("[4] = ExcelIO.WriteExcelFile1");
                Console.WriteLine("[5] = ExcelIO.WriteExcelFile2");
                Console.WriteLine("[6] = ExcelIO.WriteExcelFile3");
                Console.WriteLine("[7] = ExcelIO.WriteExcelFile4");
                Console.WriteLine("[8] = ExcelIO.WriteExcelFile5");
                Console.WriteLine("[e] = Exit");

                Console.Write("\r\nEnter choice: ");
                response = Console.ReadKey();
                Console.WriteLine("\r\n");

                Stopwatch sw   = null;
                string    path = null;

                switch (response.Key)
                {
                case ConsoleKey.D1:
                    sw   = Stopwatch.StartNew();
                    path = CsvIO.WriteCsvFile1(data);
                    break;

                case ConsoleKey.D2:
                    sw   = Stopwatch.StartNew();
                    path = CsvIO.WriteCsvFile2(data);
                    break;

                case ConsoleKey.D3:
                    sw   = Stopwatch.StartNew();
                    path = CsvIO.WriteCsvFile3();
                    break;

                case ConsoleKey.D4:
                    sw   = Stopwatch.StartNew();
                    path = ExcelIO.WriteExcelFile1(data);
                    break;

                case ConsoleKey.D5:
                    sw   = Stopwatch.StartNew();
                    path = ExcelIO.WriteExcelFile2(data);
                    break;

                case ConsoleKey.D6:
                    sw   = Stopwatch.StartNew();
                    path = ExcelIO.WriteExcelFile3(data);
                    break;

                case ConsoleKey.D7:
                    sw   = Stopwatch.StartNew();
                    path = ExcelIO.WriteExcelFile4(data);
                    break;

                case ConsoleKey.D8:
                    sw   = Stopwatch.StartNew();
                    path = ExcelIO.WriteExcelFile5();
                    break;

                case ConsoleKey.E:
                case ConsoleKey.Escape:
                    break;

                default:
                    Console.WriteLine("Invalid choice.");
                    break;
                }

                if (sw != null && sw.IsRunning)
                {
                    sw.Stop();
                    Common.WriteTime("File write operation total seconds: ", sw.Elapsed);
                    Console.WriteLine("File written to: {0}", path);
                    if (openFiles)
                    {
                        Process.Start(path);
                    }
                }
            } while (!(response.Key == ConsoleKey.E || response.Key == ConsoleKey.Escape));

            data = null;
        }
        private void Save_btn_Click(object sender, RoutedEventArgs e)
        {
            int caseSwitch = 1;

            switch (caseSwitch)
            {
            case 1:     //check for null and existing
                if (string.IsNullOrWhiteSpace(loc_srch_TextBox.Text))
                {
                    MessageBox.Show("Error! Location not selected. Try again!", "Instructions", MessageBoxButton.OK, MessageBoxImage.Information);
                    break;
                }

                if (DatePicker.SelectedDate == null)
                {
                    MessageBox.Show("Error! Date not selected. Try again!", "Instructions", MessageBoxButton.OK, MessageBoxImage.Information);
                    break;
                }

                if (hour_text_box.Text == "Hour" || minute_text_box.Text == "Minute" || string.IsNullOrWhiteSpace(minute_text_box.Text) || string.IsNullOrWhiteSpace(hour_text_box.Text))
                {
                    MessageBox.Show("Error! Time not selected. Try Again!", "Instructions", MessageBoxButton.OK, MessageBoxImage.Information);
                    break;
                }



                else
                {
                    goto case 5;     //check time first
                }


            case 2:     //location input
                string[] found_line = CsvIO.findCsvLine(loc_srch_TextBox.Text, 1, "locations.csv");
                if (found_line[0] == "Error 1! Record Not Found. Please try again.")
                {
                    MessageBoxResult result_loc = MessageBox.Show(loc_srch_TextBox.Text + " location not found in the database! Do you want to add as new location?", "Instructions", MessageBoxButton.YesNo, MessageBoxImage.Question);
                    if (result_loc == MessageBoxResult.Yes)
                    {
                        CsvIO.importCSV("locations.csv", "id,locationName", loc_srch_TextBox.Text);
                        MessageBox.Show("Location: " + loc_srch_TextBox.Text + "\n Added successful!", "Instructions", MessageBoxButton.OK, MessageBoxImage.Information);
                        string[] newloc = CsvIO.findCsvLine(loc_srch_TextBox.Text, 1, "locations.csv");
                        visit1.Event_id            = newloc[0];
                        visit1.Visit_location_name = newloc[1];
                        goto case 4;
                    }
                    else
                    {
                        MessageBox.Show("Input existing location.", "Instructions", MessageBoxButton.OK, MessageBoxImage.Information);
                        loc_srch_TextBox.Text = String.Empty;
                        break;
                    }
                }
                else
                {
                    visit1.Event_id            = found_line[0];
                    visit1.Visit_location_name = found_line[1];
                    goto case 4;
                }

            case 3:    //date check
                string           date   = DatePicker.SelectedDate.Value.ToString("MM/dd/yyyy");
                MessageBoxResult result = MessageBox.Show("Is that the correct date? \n" + date, "Date Validation", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (result == MessageBoxResult.Yes)
                {
                    visit1.Event_date = date;
                    //Visit.addToCsvVisit(visit1.User_name, visit1.User_phone, visit1.Visit_location, visit1.Visit_date);
                    goto case 2;
                }
                else
                {
                    MessageBox.Show("Please try again!", "Instructions", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                break;

            case 4:     //correct location check
                MessageBoxResult result2 = MessageBox.Show("Is that the correct location? \n" + visit1.Visit_location_name, "Location Found", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (result2 == MessageBoxResult.Yes)
                {
                    string header = "VisitId,UserName,UserPhone,LocationID,LocationName,Date,Time";
                    string toCsv  = visit1.User_name + "," + visit1.User_phone + "," + visit1.Event_id + "," + visit1.Visit_location_name + "," + visit1.Event_date + "," + visit1.Event_time;
                    CsvIO.importCSV("visit.csv", header, toCsv);
                    MessageBox.Show("Visit added successful!", "Instructions", MessageBoxButton.OK, MessageBoxImage.Information);
                    break;
                }
                else
                {
                    MessageBox.Show("Try Again.", "Instructions", MessageBoxButton.OK, MessageBoxImage.Information);
                    loc_srch_TextBox.Text = String.Empty;
                    break;
                }

            case 5:     //Time validation
                bool success1 = Int32.TryParse(hour_text_box.Text, out int hours);
                bool success2 = Int32.TryParse(minute_text_box.Text, out int minutes);

                if (success1 && success2 && hours >= 0 && hours <= 23 && minutes >= 0 && minutes <= 59)
                {
                    visit1.Event_time = hours + ":" + minutes;

                    if (minutes < 10)
                    {
                        visit1.Event_time = String.Empty;
                        string minutes_0 = string.Format("0{0}", minutes);
                        visit1.Event_time = hours + ":" + minutes_0;
                    }

                    MessageBoxResult result_time = MessageBox.Show("Is that the correct Time? \n" + visit1.Event_time, "Time Validation", MessageBoxButton.YesNo, MessageBoxImage.Question);
                    if (result_time == MessageBoxResult.Yes)
                    {
                        goto case 3;
                    }
                    else
                    {
                        visit1.Event_time = String.Empty;
                        MessageBox.Show("Please input time again!", "Instructions", MessageBoxButton.OK, MessageBoxImage.Information);
                        break;
                    }
                }
                else
                {
                    MessageBox.Show("Invalid Time Input! Please Try Again! ", "Instructions", MessageBoxButton.OK, MessageBoxImage.Information);
                    break;
                }
            }
        }
Ejemplo n.º 16
0
        public void ImportCSVFileTest()
        {
            List <IShellItem> shellItems = CsvIO.ImportCSVFile(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + @"\TestResource\raw.csv");

            Assert.AreNotEqual(shellItems.Count, 0);
        }