0% found this document useful (0 votes)
19 views4 pages

Muni EXER 1

The document contains code for a student registration form application in C#. It defines classes to handle student registration information, form input validation, and writing registration data to a text file. The main form allows selecting courses and gender from dropdowns and collecting student details like name, birthday, number etc. On registering, the data is validated and written line by line to a text file.

Uploaded by

Saiden Abbas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views4 pages

Muni EXER 1

The document contains code for a student registration form application in C#. It defines classes to handle student registration information, form input validation, and writing registration data to a text file. The main form allows selecting courses and gender from dropdowns and collecting student details like name, birthday, number etc. On registering, the data is validated and written line by line to a text file.

Uploaded by

Saiden Abbas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsApp1
{
public partial class FormLab1 : Form
{
public FormLab1()
{
InitializeComponent();
}

private void FormLab1_Load(object sender, EventArgs e)


{

private void btnCreate_Click(object sender, EventArgs e)


{
FormFileName file = new FormFileName();
file.ShowDialog();

string getInput = txtInput.Text;


string docPath =
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
StreamWriter createdFile = new StreamWriter(Path.Combine(docPath,
FormFileName.setFileName));
{
createdFile.WriteLine(getInput);
Console.WriteLine(getInput);

txtInput.Clear();

}
}
}
}

using System;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
public partial class FormFileName : Form
{
public static string setFileName;
public FormFileName()
{
InitializeComponent();
}

private void btnOkay_Click(object sender, EventArgs e)


{
setFileName = txtFileName.Text + ".txt";
this.Close();
txtFileName.Clear();

FrmRegistration filename = new FrmRegistration();


filename.ShowDialog();

}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
public partial class FrmRegistration : Form
{
public static string SetFileName;

public long StudentNumber(string sn)


{
studentNumber = long.Parse(sn);
return studentNumber;
}

public long ContactNo(string cn)


{
if (Regex.IsMatch(cn, @"^[0-9]{10,11}$")) {
ContactNum = long.Parse(cn);
} else {
throw new FormatException("Please Enter a Number!");
}
return ContactNum;
}
public string FullName(string lN, string fN, string mI)
{
if (Regex.IsMatch(lN, @"^[a-zA-Z]+$") || Regex.IsMatch(fN, @"^[a-zA-Z]+$") ||
Regex.IsMatch(mI, @"^[a-zA-Z]+$")) {
fullName = lN + ", " + fN + ", " + mI;
} else {
throw new FormatException("Wrong Format");
}
return fullName;
}
public int Age(string age)
{
if (Regex.IsMatch(age, @"^[0-9]{1,3}$")) {
yearsOld = Int32.Parse(age);
} else {
throw new FormatException("Please Enter a Number");
}
return yearsOld;
}

public FrmRegistration()
{
InitializeComponent();
}

public class RegistrationInfo


{
public static int studentNo = 0;
public static string fullName = "";
public static int ages = 0;
public static string birthday = "";
public static string program = "";
public static string gender = "";
public static int contactNo = 0;
}

private string fullName;


private int yearsOld;
private long ContactNum;
private long studentNumber;

private void button1_Click(object sender, EventArgs e)


{

private void btnRegister_Click(object sender, EventArgs e)


{
string docPath =
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
StreamWriter createdFile = new StreamWriter(Path.Combine(docPath,
FormFileName.setFileName));
StreamWriter Contents;
Contents = createdFile;

string stuNum = txtStudentNo.Text + ": " + txtStudentNo.Text;


string fullName = "Full Name : " + (txtLastName.Text + " " +
txtFirstName.Text + " " + txtMi.Text);
string yearOld = lblAge.Text + ": " + txtAge.Text;
string birthDay = lblBirthday.Text + ": " + dtBirthday.Value.ToString("yyyy-
MM-dd");
string course = lblPrograms.Text + ": " + cbPrograms.SelectedItem.ToString();
string gender = lblGender.Text + ": " + cbGender.SelectedItem.ToString();
string conNumber = lblContactNum.Text + ": " + txtContactNo.Text.ToString();

Contents.WriteLine(stuNum);
Contents.WriteLine(fullName);
Contents.WriteLine(yearOld);
Contents.WriteLine(birthDay);
Contents.WriteLine(course);
Contents.WriteLine(gender);
Contents.WriteLine(conNumber);

Contents.Close();
txtStudentNo.Clear();
txtFirstName.Clear();
txtLastName.Clear();
txtMi.Clear();
txtAge.Clear();
txtContactNo.Clear();
}

private void frmRegistration_Load(object sender, EventArgs e)


{
string[] courses = new string[]
{
"BS Information Technology",
"BS Computer Science",
"BS Business Administration",
};
for (int x = 0; x < 3; x++) {
cbPrograms.Items.Add(courses[x].ToString());
}
string[] Gender = new string[]
{
"Male",
"Female",
"Others"
};
for (int x = 0; x < 3; x++) {
cbGender.Items.Add(Gender[x].ToString());
}

}
}

You might also like