Ejemplo n.º 1
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);
     }
 }
        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.º 3
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;
            }
        }
        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;
                }
            }
        }