using System; using System.Windows.Forms; namespace CSC330_CSharp_Midterm { public partial class AdminForm : Form { public AdminForm() { InitializeComponent(); dataGridView1.DataSource = Requests.Select("SELECT * FROM Guest"); // install the guest data source } private void radioButton1_CheckedChanged(object sender, EventArgs e) { dataGridView1.DataSource = Requests.Select("SELECT * FROM Guest"); // install the guest data source } private void radioButton2_CheckedChanged(object sender, EventArgs e) { dataGridView1.DataSource = Requests.Select("SELECT * FROM Member"); // install the guest member source } private void radioButton3_CheckedChanged(object sender, EventArgs e) { dataGridView1.DataSource = Requests.Select("SELECT * FROM Owner"); // install the owner data source } private void radioButton4_CheckedChanged(object sender, EventArgs e) { dataGridView1.DataSource = Requests.Select("SELECT * FROM Gym"); // install the gym data source } private void radioButton5_CheckedChanged(object sender, EventArgs e) { dataGridView1.DataSource = Requests.Select("SELECT * FROM Employee"); // install the employee data source } private void button1_Click(object sender, EventArgs e) { if (radioButton1.Checked == true) // table guest { if (Requests.Request("DELETE FROM Guest") == "") // delete data from the table Guest from the database { //read data from table Guest to database for (int i = 0; i < dataGridView1.Rows.Count; i++) { if (dataGridView1.Rows[i].Cells[0].Value != null) { Requests.Request("INSERT INTO [Guest] ([Name], [DOB], [Address], [Cost], [Day]) VALUES ('" + dataGridView1.Rows[i].Cells[0].Value + "', '" + dataGridView1.Rows[i].Cells[1].Value + "', '" + dataGridView1.Rows[i].Cells[2].Value + "', '" + dataGridView1.Rows[i].Cells[3].Value + "', '" + dataGridView1.Rows[i].Cells[4].Value + "')"); } } MessageBox.Show("The data has been successfully saved!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Error writing to the database!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (radioButton2.Checked == true) // table Member { if (Requests.Request("DELETE FROM Member") == "") //delete data from the table Member from the database { //read data from table Member to database for (int i = 0; i < dataGridView1.Rows.Count; i++) { if (dataGridView1.Rows[i].Cells[0].Value != null) { Requests.Request("INSERT INTO [Member] ([Name], [DOB], [Address], [Month], [Cost], [Weight], [Height], [Goal], [NumberOfCreditCard]) VALUES ('" + dataGridView1.Rows[i].Cells[0].Value + "', '" + dataGridView1.Rows[i].Cells[1].Value + "', '" + dataGridView1.Rows[i].Cells[2].Value + "', '" + dataGridView1.Rows[i].Cells[3].Value + "', '" + dataGridView1.Rows[i].Cells[4].Value + "', '" + dataGridView1.Rows[i].Cells[5].Value + "', '" + dataGridView1.Rows[i].Cells[6].Value + "', '" + dataGridView1.Rows[i].Cells[7].Value + "', '" + dataGridView1.Rows[i].Cells[8].Value + "')"); } } MessageBox.Show("The data has been successfully saved!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Error writing to the database!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (radioButton3.Checked == true) // table Owner { if (Requests.Request("DELETE FROM Owner") == "") //delete data from the table Owner from the database { //read data from table Owner to database for (int i = 0; i < dataGridView1.Rows.Count; i++) { if (dataGridView1.Rows[i].Cells[0].Value != null) { Requests.Request("INSERT INTO [Owner] ([Name], [DOB], [Address]) VALUES ('" + dataGridView1.Rows[i].Cells[0].Value + "', '" + dataGridView1.Rows[i].Cells[1].Value + "', '" + dataGridView1.Rows[i].Cells[2].Value + "')"); } } MessageBox.Show("The data has been successfully saved!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Error writing to the database!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (radioButton4.Checked == true) // table Gym { if (Requests.Request("DELETE FROM Gym") == "") //delete data from the table Gym from the database { //read data from table Gym to database for (int i = 0; i < dataGridView1.Rows.Count; i++) { if (dataGridView1.Rows[i].Cells[0].Value != null) { Requests.Request("INSERT INTO [Gym] ([Name], [Equipment], [Quantity]) VALUES ('" + dataGridView1.Rows[i].Cells[0].Value + "', '" + dataGridView1.Rows[i].Cells[1].Value + "', '" + dataGridView1.Rows[i].Cells[2].Value + "')"); } } MessageBox.Show("The data has been successfully saved!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Error writing to the database!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (radioButton5.Checked == true) // table Employee { if (Requests.Request("DELETE FROM Employee") == "") // delete data from the table Employee from the database { //read data from table Employee to database for (int i = 0; i < dataGridView1.Rows.Count; i++) { if (dataGridView1.Rows[i].Cells[0].Value != null) { Requests.Request("INSERT INTO [Employee] ([Name], [DOB], [Address], [Etype]) VALUES ('" + dataGridView1.Rows[i].Cells[0].Value + "', '" + dataGridView1.Rows[i].Cells[1].Value + "', '" + dataGridView1.Rows[i].Cells[2].Value + "', '" + dataGridView1.Rows[i].Cells[3].Value + "')"); } } MessageBox.Show("The data has been successfully saved!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Error writing to the database!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }