private void NAddStaffBtn_Click(object sender, EventArgs e) { AddStaffMember newStaffPage = new AddStaffMember(); this.Hide(); newStaffPage.ShowDialog(); }
private void AddOperation() { con.Open(); SqlCommand cmd = con.CreateCommand(); cmd.CommandType = CommandType.Text; string memberTypeValue = ""; bool memberTypeisChecked = adedemicRadio.Checked; if (memberTypeisChecked) { memberTypeValue = adedemicRadio.Text; } else { memberTypeValue = nonAcedemicRadio.Text; } string accessLevelValue = ""; bool accessLevelisChecked = adminRadio.Checked; if (accessLevelisChecked) { accessLevelValue = adminRadio.Text; } else { accessLevelValue = userRadio.Text; } string genderValue = ""; bool genderisChecked = maleRadioButton2.Checked; if (genderisChecked) { genderValue = maleRadioButton2.Text; } else { genderValue = femaleRadioButton1.Text; } cmd.CommandText = "INSERT INTO staff(memberType,accessLevel,fullName,name,gender,NIC,DOB,address,phoneNo,email,subject,pastSchool,serviceYears,salary,password,subject2) VALUES('" + memberTypeValue + "','" + accessLevelValue + "','" + NametextBox1.Text + "','" + nameTextBox2.Text + "','" + genderValue + "','" + NICTextBox.Text + "','" + dateTimePicker1.Value + "','" + addressTextBox.Text + "','" + phNoTextBox.Text + "','" + emailTextBox1.Text + "','" + subTextBox1.Text + "','" + pastSchTextBox.Text + "','" + Int32.Parse(serviceYrsTextBox.Text) + "','" + Convert.ToDouble(salaryTextBox.Text) + "','" + NICTextBox.Text + "','" + subTextBox2.Text + "')"; cmd.ExecuteNonQuery(); con.Close(); con.Open(); SqlCommand command; SqlDataReader dataReader; string query = "SELECT staffID FROM staff where NIC = '" + NICTextBox.Text + "' and email = '" + emailTextBox1.Text + "' and fullName = '" + NametextBox1.Text + "'"; command = new SqlCommand(query, con); dataReader = command.ExecuteReader(); if (dataReader.Read()) { staffID = dataReader.GetValue(0).ToString(); } dataReader.Close(); command.Dispose(); con.Close(); con.Open(); SqlCommand cmd2 = con.CreateCommand(); cmd2.CommandType = CommandType.Text; cmd2.CommandText = "insert into SalaryRecord(staffID,salary,date) values(" + staffID + "," + salaryTextBox.Text + ",'" + DateTime.Now.ToString("M/d/yyyy") + "')"; cmd2.ExecuteNonQuery(); con.Close(); DialogResult dlgResult = MessageBox.Show("Do You Want To Add More Staff", "Staff Member Added Succesfully!", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dlgResult == DialogResult.Yes) { AddStaffMember addstaffMember = new AddStaffMember(); this.Hide(); addstaffMember.ShowDialog(); } else { ViewStaffMembers viewStaff = new ViewStaffMembers(); this.Hide(); viewStaff.ShowDialog(); } }