0% found this document useful (0 votes)
8 views

07 LAB Panganiban

The document contains C# code for a club registration system, including forms for registering and updating club members. It defines a class for handling database queries related to club members, including methods for displaying, registering, and updating member information. The system utilizes a SQL database for storing member data and provides a user interface for interaction.

Uploaded by

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

07 LAB Panganiban

The document contains C# code for a club registration system, including forms for registering and updating club members. It defines a class for handling database queries related to club members, including methods for displaying, registering, and updating member information. The system utilizes a SQL database for storing member data and provides a user interface for interaction.

Uploaded by

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

Tremaine Rixter Panganiban

BSIT 3.1B

FrmClubRegistration:
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Data.SqlClient;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading;

using System.Threading.Tasks;

using System.Windows.Forms;

namespace FrmClubRegistration

public partial class FrmClubRegistration : Form

private ClassRegistrationQuery clubRegistrationQuery;

private int ID, Age, count;

private string FirstName, MiddleName, LastName, Gender, Program;

private long StudentID;

private void btnUpdate_Click(object sender, EventArgs e)

FrmUpdateMember frmUpdateMember = new FrmUpdateMember();

frmUpdateMember.Show();
}

private void btnRefresh_Click(object sender, EventArgs e)

RefreshListOfClubMembers();

public FrmClubRegistration()

InitializeComponent();

clubRegistrationQuery = new ClassRegistrationQuery();

public void RefreshListOfClubMembers()

clubRegistrationQuery.DisplayList();

dataGridView1.DataSource = clubRegistrationQuery.bindingSource;

public int RegistrationID()

return count++;

private void FrmClubRegistration_Load(object sender, EventArgs e)

RefreshListOfClubMembers();

string[] ListOfProgram = new string[]


{

"BS Information Technology",

"BS Computer Science",

"BS Information System",

"BS in Accountancy",

"BS in Hospitality Management",

"BS in Tourism Management"

};

for (int i = 0; i < 6; i++)

cbProgram.Items.Add(ListOfProgram[i].ToString());

string[] ListOfGender = new string[]

"Male",

"Female"

};

for (int i = 0; i < 2; i++)

cbGender.Items.Add(ListOfGender[i].ToString());

private void btnRegister_Click(object sender, EventArgs e)

ID = RegistrationID();

StudentID = long.Parse(tbStudentID.Text);

FirstName = tbFName.Text;
MiddleName = tbMName.Text;

LastName = tbLName.Text;

Age = int.Parse(tbAge.Text);

Gender = cbGender.Text;

Program = cbProgram.Text;

clubRegistrationQuery.RegisterStudent(ID, StudentID, FirstName, MiddleName, LastName, Age,


Gender, Program);

RegistrationID();

FrmUpdateMember:
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;

namespace FrmClubRegistration

public partial class FrmUpdateMember : Form

ClassRegistrationQuery clubRegistrationQuery = new ClassRegistrationQuery();

public FrmUpdateMember()
{

InitializeComponent();

clubRegistrationQuery.IdSelect(cbStudentID);

private void FrmUpdateMember_Load(object sender, EventArgs e)

clubRegistrationQuery.IdSelect(cbStudentID);

string[] ListOfProgram = new string[]

"BS Information Technology",

"BS Computer Science",

"BS Information System",

"BS in Accountancy",

"BS in Hospitality Management",

"BS in Tourism Management"

};

for (int i = 0; i < 6; i++)

cbProgram.Items.Add(ListOfProgram[i].ToString());

string[] ListOfGender = new string[]

"Male",

"Female"

};

for (int i = 0; i < 2; i++)


{

cbGender.Items.Add(ListOfGender[i].ToString());

private void cbStudentID_SelectedIndexChanged(object sender, EventArgs e)

clubRegistrationQuery.AutoSearch(txtFName, txtMName, txtLName, txtAge, cbGender,


cbProgram, Convert.ToInt32(cbStudentID.Text));

private void btnConfirm_Click(object sender, EventArgs e)

clubRegistrationQuery.UpdateStudent(Convert.ToInt32(cbStudentID.Text), txtFName.Text,
txtLName.Text, txtMName.Text, Convert.ToInt32(txtAge.Text), cbGender.Text, cbProgram.Text);

FrmClubRegistration frmClubRegistration = new FrmClubRegistration();

frmClubRegistration.RefreshListOfClubMembers();

ClubRegistrationQuery:
using System;

using System.Collections.Generic;

using System.Data.SqlClient;

using System.Data;

using System.Linq;

using System.Text;
using System.Threading.Tasks;

using System.Windows.Forms;

namespace FrmClubRegistration

internal class ClassRegistrationQuery

private SqlConnection sqlConnect;

private SqlCommand sqlCommand;

private SqlDataAdapter sqlAdapter;

private SqlDataReader sqlReader;

public DataTable dataTable;

public BindingSource bindingSource;

private string connectionString;

public ClassRegistrationQuery()

string connectionString = @"Data


Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Guevarra\source\repos\FrmClubRegistra
tion\FrmClubRegistration\ClubDB.mdf;Integrated Security=True";

sqlConnect = new SqlConnection(connectionString);

dataTable = new DataTable();

bindingSource = new BindingSource();

public bool DisplayList()

string ViewClubMembers = "SELECT StudentId, FirstName, MiddleName, LastName, Age, Gender,


Program FROM ClubMembers";

sqlAdapter = new SqlDataAdapter(ViewClubMembers, sqlConnect);


dataTable.Clear();

sqlAdapter.Fill(dataTable);

bindingSource.DataSource = dataTable;

return true;

public bool RegisterStudent(int ID, long StudentID, string FirstName, string MiddleName,string
LastName,

int Age, string Gender, string Program)

sqlCommand = new SqlCommand("INSERT INTO ClubMembers VALUES(@ID, @StudentID,


@FirstName, @MiddleName, " +

"@LastName, @Age, @Gender, @Program)", sqlConnect);

sqlCommand.Parameters.Add("@ID", SqlDbType.Int).Value = ID;

sqlCommand.Parameters.Add("@StudentID", SqlDbType.BigInt).Value = StudentID;

sqlCommand.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = FirstName;

sqlCommand.Parameters.Add("@MiddleName", SqlDbType.VarChar).Value = MiddleName;

sqlCommand.Parameters.Add("@LastName", SqlDbType.VarChar).Value = LastName;

sqlCommand.Parameters.Add("@Age", SqlDbType.Int).Value = Age;

sqlCommand.Parameters.Add("@Gender", SqlDbType.VarChar).Value = Gender;

sqlCommand.Parameters.Add("@Program", SqlDbType.VarChar).Value = Program;

sqlConnect.Open();

sqlCommand.ExecuteNonQuery();

sqlConnect.Close();

return true;

public void IdSelect(ComboBox cb)


{

string selectId = "SELECT StudentId FROM ClubMembers ";

sqlCommand = new SqlCommand(selectId, sqlConnect);

sqlCommand.CommandText = selectId;

sqlConnect.Open();

sqlReader = sqlCommand.ExecuteReader();

while (sqlReader.Read())

cb.Items.Add(sqlReader["StudentId"].ToString());

sqlConnect.Close();

public void AutoSearch(TextBox tbFirstName, TextBox tbMiddleName, TextBox tbLastName,


TextBox tbAge, ComboBox cbGender, ComboBox cbProgram, int ID)

string selectId = "SELECT FirstName,MiddleName,LastName,Age,Gender,Program FROM


ClubMembers WHERE StudentId = @ID ";

sqlCommand = new SqlCommand(selectId, sqlConnect);

sqlCommand.Parameters.Add("@ID", SqlDbType.Int).Value = ID;

sqlCommand.CommandText = selectId;

sqlConnect.Open();

sqlReader = sqlCommand.ExecuteReader();

while (sqlReader.Read())

tbFirstName.Text = (sqlReader["FirstName"].ToString());

tbMiddleName.Text = (sqlReader["MiddleName"].ToString());

tbLastName.Text = (sqlReader["LastName"].ToString());
tbAge.Text = (sqlReader["Age"].ToString());

cbGender.Text = (sqlReader["Gender"].ToString());

cbProgram.Text = (sqlReader["Program"].ToString());

sqlConnect.Close();

public void UpdateStudent(long StudentID, string FirstName, string

MiddleName, string LastName, int Age, string Gender, string Program)

sqlCommand = new SqlCommand("UPDATE ClubMembers SET FirstName =


@FirstName,MiddleName = @MiddleName,LastName= @LastName,Age= @Age,Gender=
@Gender,Program= @Program WHERE StudentId = @StudentID", sqlConnect);

sqlCommand.Parameters.Add("@StudentID", SqlDbType.VarChar).Value = StudentID;

sqlCommand.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = FirstName;

sqlCommand.Parameters.Add("@MiddleName", SqlDbType.VarChar).Value = MiddleName;

sqlCommand.Parameters.Add("@LastName", SqlDbType.VarChar).Value = LastName;

sqlCommand.Parameters.Add("@Age", SqlDbType.Int).Value = Age;

sqlCommand.Parameters.Add("@Gender", SqlDbType.VarChar).Value = Gender;

sqlCommand.Parameters.Add("@Program", SqlDbType.VarChar).Value = Program;

sqlConnect.Open();

sqlCommand.ExecuteNonQuery();

sqlConnect.Close();

}
OUTPUT:

You might also like