private void addButton_Click(object sender, EventArgs e) { if (nameBox.Text == "" || genderBox.Text == "" || ageBox.Text == "" || phoneBox.Text == "" || salaryBox.Text == "") { MessageBox.Show("Please give all information"); return; } string name = nameBox.Text; string gender = genderBox.Text; string age = ageBox.Text; string roomNo; if (roomComboBox.Items.Count == 0) { roomNo = ""; } else { roomNo = roomComboBox.SelectedItem.ToString(); } string phone = phoneBox.Text; string salary = salaryBox.Text; staffDTO st = new staffDTO(name, gender, age, roomNo, phone, salary); staffDAO sD = new staffDAO(); sD.createStaff(st); clearFields(); }
public void deleteStaff(staffDTO st) { s.sqlConnection.Open(); string query = "delete from staffs where staffId = '" + st.StaffId + "'"; s.sqlCommand = new SqlCommand(query, s.sqlConnection); s.sqlCommand.ExecuteNonQuery(); s.sqlConnection.Close(); }
private void staffDataGridView_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { int staffId = Convert.ToInt32(staffDataGridView.Rows[e.Row.Index].Cells[0].Value.ToString()); string name = staffDataGridView.Rows[e.Row.Index].Cells[1].Value.ToString(); string gender = staffDataGridView.Rows[e.Row.Index].Cells[2].Value.ToString(); string age = staffDataGridView.Rows[e.Row.Index].Cells[3].Value.ToString(); string roomNo = staffDataGridView.Rows[e.Row.Index].Cells[4].Value.ToString(); string phone = staffDataGridView.Rows[e.Row.Index].Cells[5].Value.ToString(); string salary = staffDataGridView.Rows[e.Row.Index].Cells[6].Value.ToString(); st = new staffDTO(staffId, name, gender, age, roomNo, phone, salary); }
public void createStaff(staffDTO st) { s.sqlConnection.Open(); string query = "insert into staffs(name,gender,age,roomNo,phone,salary) values('" + st.Name + "','" + st.Gender + "','" + st.Age + "','" + st.RoomNo + "','" + st.Phone + "','" + st.Salary + "')"; s.sqlCommand = new SqlCommand(query, s.sqlConnection); s.sqlCommand.ExecuteNonQuery(); s.sqlConnection.Close(); }
public void updateStaff(staffDTO st) { s.sqlConnection.Open(); string query = "update staffs set name = '" + st.Name + "', gender = '" + st.Gender + "', age = '" + st.Age + "', roomNo = '" + st.RoomNo + "', phone = '" + st.Phone + "', salary = '" + st.Salary + "' where staffId = '" + st.StaffId + "' "; s.sqlCommand = new SqlCommand(query, s.sqlConnection); s.sqlCommand.ExecuteNonQuery(); s.sqlConnection.Close(); }
private void deleteButton_Click(object sender, EventArgs e) { if (staffDataGridView.SelectedRows.Count == 0) { MessageBox.Show("Select a row from table"); return; } int idx = staffDataGridView.SelectedRows[0].Index; int staffId = Convert.ToInt32(staffDataGridView.Rows[idx].Cells[0].Value.ToString()); string name = staffDataGridView.Rows[idx].Cells[1].Value.ToString(); string gender = staffDataGridView.Rows[idx].Cells[2].Value.ToString(); string age = staffDataGridView.Rows[idx].Cells[3].Value.ToString(); string roomNo = staffDataGridView.Rows[idx].Cells[4].Value.ToString(); string phone = staffDataGridView.Rows[idx].Cells[5].Value.ToString(); string salary = staffDataGridView.Rows[idx].Cells[6].Value.ToString(); st = new staffDTO(staffId, name, gender, age, roomNo, phone, salary); sD.deleteStaff(st); loadStaffsInfo(); }
private void staffDataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e) { bool blank = false; if (staffDataGridView.Rows[e.RowIndex].Cells[0].Value.ToString() == "") { blank = true; } if (staffDataGridView.Rows[e.RowIndex].Cells[1].Value.ToString() == "") { blank = true; } if (staffDataGridView.Rows[e.RowIndex].Cells[2].Value.ToString() == "") { blank = true; } if (staffDataGridView.Rows[e.RowIndex].Cells[3].Value.ToString() == "") { blank = true; } if (staffDataGridView.Rows[e.RowIndex].Cells[4].Value.ToString() == "") { } if (staffDataGridView.Rows[e.RowIndex].Cells[5].Value.ToString() == "") { blank = true; } if (staffDataGridView.Rows[e.RowIndex].Cells[6].Value.ToString() == "") { blank = true; } if (blank) { loadStaffsInfo(); return; } int staffId = Convert.ToInt32(staffDataGridView.Rows[e.RowIndex].Cells[0].Value.ToString()); string name = staffDataGridView.Rows[e.RowIndex].Cells[1].Value.ToString(); string gender = staffDataGridView.Rows[e.RowIndex].Cells[2].Value.ToString(); string age = staffDataGridView.Rows[e.RowIndex].Cells[3].Value.ToString(); string roomNo = staffDataGridView.Rows[e.RowIndex].Cells[4].Value.ToString(); string phone = staffDataGridView.Rows[e.RowIndex].Cells[5].Value.ToString(); string salary = staffDataGridView.Rows[e.RowIndex].Cells[6].Value.ToString(); DataSet ds = new DataSet(); roomDAO rD = new roomDAO(); ds = rD.getRooms(); bool flag = false; foreach (DataRow row in ds.Tables[0].Rows) { string rN = row["roomNo"].ToString(); if (roomNo == rN) { flag = true; break; } } if (flag == false && roomNo != "") { loadStaffsInfo(); return; } st = new staffDTO(staffId, name, gender, age, roomNo, phone, salary); sD.updateStaff(st); loadStaffsInfo(); }