REGISTRATION
unknown
csharp
4 years ago
4.9 kB
3
Indexable
using System; using System.Windows.Forms; using System.Text.RegularExpressions; namespace CamposanoCRUDFirebaseFinalTask.Forms.Menu { public partial class Form_Register : Form { private string _FullName; private int _Age; private long _ContactNo, _StudentNo; public long StudentNumber(string studNum) { try { _StudentNo = long.Parse(studNum); if(studNum == "") { throw new ArgumentException(MessageBox.Show("Student number field is empty").ToString()); } } catch (Exception e) { Console.WriteLine(e.Message); } return _StudentNo; } public long ContactNo(string Contact) { try { if (Regex.IsMatch(Contact, @"^[0-9]{10,11}$")) { _ContactNo = long.Parse(Contact); } else if (Contact == "") { throw new ArgumentException(MessageBox.Show("Contact number field is empty").ToString()); } else { throw new ArgumentException(MessageBox.Show("Student number field is out of range").ToString()); } } catch (Exception e) { Console.WriteLine(e.Message); } return _ContactNo; } public string FullName(string LastName, string FirstName, string MiddleInitial) { try { if (Regex.IsMatch(LastName, @"^[a-zA-Z]+$") || Regex.IsMatch(FirstName, @"^[a-zA-Z]+$") || Regex.IsMatch(MiddleInitial, @"^[a-zA-Z]+$")) { _FullName = LastName + ", " + FirstName + ", " + MiddleInitial; } else { throw new ArgumentException(MessageBox.Show("Please check your full name fields and try again").ToString()); } } catch (Exception e) { Console.WriteLine(e.Message); } return _FullName; } public int Age(string age) { try { if (Regex.IsMatch(age, @"^[0-9]{1,3}$")) { _Age = Int32.Parse(age); } else if (age == "") { throw new ArgumentException(MessageBox.Show("Age field is empty").ToString()); } else { throw new ArgumentException(MessageBox.Show("Age index is invalid").ToString()); } } catch (Exception e) { Console.WriteLine(e.Message); } return _Age; } public Form_Register() { InitializeComponent(); } private void btnRegister_Click(object sender, EventArgs e) { try { this.TopMost = false; StudentInformationClass.SetFullName = FullName(txtLastName.Text, txtFirstName.Text, txtMiddleInitial.Text); StudentInformationClass.SetStudentNo = (int)StudentNumber(txtStudentNo.Text); StudentInformationClass.SetProgram = cbPrograms.Text; StudentInformationClass.SetGender = cbGender.Text; StudentInformationClass.SetContactNo = Convert.ToInt32(txtContactNo.Text); StudentInformationClass.SetAge = Age(txtAge.Text); StudentInformationClass.SetBirthDay = datePickerBirthday.Value.ToString("yyyy-MM-dd"); } catch (FormatException) { MessageBox.Show("Please input numbers only in\nContact Number and Student No. fields", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } Form_Confirmation frm = new Form_Confirmation(); frm.ShowDialog(); } private void Form_Register_Load(object sender, EventArgs e) { string[] ListOfProgram = new string[] { "BS Information Technology", "BS Computer Science", "BS Information Systems", "BS in Accountancy", "BS in Hospitality Management", "BS in Tourism Management" }; for (int i = 0; i < 6; i++) { cbPrograms.Items.Add(ListOfProgram[i].ToString()); } } } }
Editor is loading...