private List <EnrollStudent> GenerateListOfEnrollStudentsWithBldgData(List <EnrollBuilding> buildingsList, int numberOfStudentsMIN, int numberOfStudentsMax) { int trackRollingGradeState = 1; List <EnrollStudent> ListOfStudents = new List <EnrollStudent>(); foreach (EnrollBuilding enrollBuilding in buildingsList) { rnd = new Random(); int numberOfStudentsToGenerateForThisBldg = rnd.Next(numberOfStudentsMIN, numberOfStudentsMax); System.Threading.Thread.Sleep(50); for (int i = 0; i < numberOfStudentsToGenerateForThisBldg; i++) { enrollStudent = new EnrollStudent(); if (enrollBuilding.School_Id != "") { enrollStudent.School_Id = enrollBuilding.School_Id; } if (enrollBuilding.School_Name != "") { enrollStudent.School_Name = enrollBuilding.School_Name; } if (MB_sisIDText.Text != "") { enrollStudent.Sis_Id = MB_sisIDText.Text + trackingStudentRollingID; } if (MB_LastName.Text != "") { enrollStudent.Last_Name = MB_LastName.Text + trackingStudentRollingID; } if (MB_FirstName.Text != "") { enrollStudent.First_Name = MB_FirstName.Text + trackingStudentRollingID; } if (MB_MiddleName.Text != "") { enrollStudent.Middle_Name = MB_MiddleName.Text + trackingStudentRollingID; } #region Grade if (MB_Rolling_Chbx.Checked) { if (trackRollingGradeState >= 0 || trackRollingGradeState <= 14) { enrollStudent.Grade = GetStudentGradeText(trackRollingGradeState); if (trackRollingGradeState == 14) { trackRollingGradeState = 1; } else { trackRollingGradeState++; } } else { enrollStudent.Grade = "In generating a grade name, the number was not between 1 and 14 for the db grade ID"; } } else if (MB_RandomGradeCHBX.Checked) { rnd = new Random(); enrollStudent.Grade = GetStudentGradeText(rnd.Next(1, 15)); System.Threading.Thread.Sleep(5); } else { enrollStudent.Grade = MB_Grade_ComboBox.Text; } #endregion if (MB_Username.Text != "") { enrollStudent.Username = MB_Username.Text + trackingStudentRollingID; } if (MB_Password.Text != "") { if (MB_AutoIncrementPW.Checked) { enrollStudent.Password = MB_Password.Text + trackingStudentRollingID; } else { enrollStudent.Password = MB_Password.Text; } } ListOfStudents.Add(enrollStudent); trackingStudentRollingID++; } }//Ends Foreach //Adds Each Student To a line in string builder foreach (EnrollStudent student in ListOfStudents) { csvcontent.AppendLine(student.School_Id + "," + student.School_Name + "," + student.Sis_Id + "," + student.Last_Name + "," + student.First_Name + "," + student.Middle_Name + "," + student.Grade + "," + student.Username + "," + student.Password); } return(ListOfStudents); }
/// <summary> /// Single Building Generate CSV Button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void generateCSVButton_Click(object sender, EventArgs e) { //Checks to see if the file exists, if it does it deletes it so we can start fresh each time string fullFillePathAndFileName = filePathText.Text + fileName_text.Text; if (File.Exists(fullFillePathAndFileName)) { File.Delete(fullFillePathAndFileName); } StringBuilder csvcontent = new StringBuilder(); //Builds Header Information Based on File Header Text Feild csvcontent.AppendLine(file_header_text.Text); #region Build The Student Object From The Form studentsForCSVFileListSmallBuilding = new List <EnrollStudent>(); int trackRollingGradeState = 1; for (int i = 0; i < studentsToGenerateNumber.Value; i++) { enrollStudent = new EnrollStudent(); if (school_id_text.Text != "") { enrollStudent.School_Id = school_id_text.Text; } if (school_name_text.Text != "") { enrollStudent.School_Name = school_name_text.Text; } if (sis_id_student_text.Text != "") { enrollStudent.Sis_Id = sis_id_student_text.Text + trackingStudentRollingID; } if (last_name_text.Text != "") { enrollStudent.Last_Name = last_name_text.Text + trackingStudentRollingID; } if (first_name_text.Text != "") { enrollStudent.First_Name = first_name_text.Text + trackingStudentRollingID; } if (middle_name_text.Text != "") { enrollStudent.Middle_Name = middle_name_text.Text + trackingStudentRollingID; } #region Grade if (rolling_grade_checkbox.Checked) { if (trackRollingGradeState >= 0 || trackRollingGradeState <= 14) { enrollStudent.Grade = GetStudentGradeText(trackRollingGradeState); if (trackRollingGradeState == 14) { trackRollingGradeState = 1; } else { trackRollingGradeState++; } } else { enrollStudent.Grade = "In generating a grade name, the number was not between 1 and 14 for the db grade ID"; } } else if (randomize_grade_checkbox.Checked) { rnd = new Random(); enrollStudent.Grade = GetStudentGradeText(rnd.Next(1, 15)); System.Threading.Thread.Sleep(5); } else { enrollStudent.Grade = grade_combo_box.Text; } #endregion if (username_text.Text != "") { enrollStudent.Username = username_text.Text + trackingStudentRollingID; } if (password_text.Text != "") { if (auto_increment_password_checkbox.Checked) { enrollStudent.Password = password_text.Text + trackingStudentRollingID; } else { enrollStudent.Password = password_text.Text; } } studentsForCSVFileListSmallBuilding.Add(enrollStudent); trackingStudentRollingID++; } #endregion //Adds Each Student To a line in string builder foreach (EnrollStudent student in studentsForCSVFileListSmallBuilding) { csvcontent.AppendLine(student.School_Id + "," + student.School_Name + "," + student.Sis_Id + "," + student.Last_Name + "," + student.First_Name + "," + student.Middle_Name + "," + student.Grade + "," + student.Username + "," + student.Password); } //Creates the file based on the file path and file name File.AppendAllText(fullFillePathAndFileName, csvcontent.ToString()); }