private void btnEditStudent_Click(object sender, RoutedEventArgs e) { if (TableValues(0) != null) { DAOStudents dao = new DAOStudents(); TOStudent i = new TOStudent(); i = dao.Selection(TableValues(0)); REG_student reg_s = new REG_student(i); reg_s.ShowDialog(); LoadScreen(); } }
private void tblStudents_MouseDoubleClick(object sender, MouseButtonEventArgs e) { if (TableValues(0) != null) { DAOStudents dao = new DAOStudents(); TOStudent i = new TOStudent(); i = dao.Selection(TableValues(0)); REG_student reg_s = new REG_student(i); reg_s.ShowDialog(); LoadScreen(); } }
public List <TOStudent> LoadStudents(int id) { List <TOStudent> i = new List <TOStudent>(); try { string sql = "select * from tbl_student where class_id = " + id + ";"; con = ConnectionFactory.Connection(); MySqlCommand cmd = new MySqlCommand(sql, con); con.Open(); MySqlDataReader dtreader = cmd.ExecuteReader(); while (dtreader.Read())//If there's any data. { TOStudent x = new TOStudent(); x.Student_id = dtreader.GetInt16("student_id"); x.Student_name = dtreader.GetString("student_name"); x.Student_ctr = dtreader.GetString("student_ctr"); x.Student_status = dtreader.GetString("student_status"); x.Student_subscriptionDate = dtreader.GetString("student_subscriptionDate"); //verifying if class exists. var _classID = dtreader["class_id"] as int?; if (_classID.HasValue) { x.Class_id = dtreader.GetInt16("class_id"); } else { x.Class_id = 0; } i.Add(x); } con.Close(); } catch (MySqlException e) { throw new Exception(e.Message); } return(i); }
public bool Registration(TOStudent student, TOResponsable resp) { bool i = false; TOClass _class = new TOClass(); try { if (resp != null) { string insert_resp = @"insert into tbl_resp(resp_name, resp_rg, resp_cpf, resp_birthDate, resp_sex, resp_phone, resp_whatsApp, resp_cep, resp_state, resp_city, resp_block, resp_street,resp_number, resp_obs) values('" + resp.Resp_name + "', '" + resp.Resp_rg + "', '" + resp.Resp_cpf + "', '" + resp.Resp_birthDate + "', '" + resp.Resp_sex + "', '" + resp.Resp_phone + "', '" + resp.Resp_whatsApp + "', '" + resp.Resp_cep + "', '" + resp.Resp_state + "', '" + resp.Resp_city + "', '" + resp.Resp_block + "', '" + resp.Resp_street + "', '" + resp.Resp_number + "', '" + resp.Resp_obs + "');"; con = ConnectionFactory.Connection(); MySqlCommand cmdInsertResp = new MySqlCommand(insert_resp, con); con.Open(); cmdInsertResp.ExecuteNonQuery(); con.Close(); string select_resp = "select resp_id from tbl_resp where resp_rg = '" + resp.Resp_rg + "';"; MySqlCommand cmdSelect = new MySqlCommand(select_resp, con); con.Open(); MySqlDataReader reader = cmdSelect.ExecuteReader(); if (reader.Read()) { resp.Resp_id = reader.GetInt16("resp_id"); } con.Close(); string sql = @"insert into tbl_student(student_name, student_ctr, student_status, student_subscriptionDate, student_rg, student_cpf, student_birthDate, student_sex, student_phone, student_whatsApp, student_cep, student_state, student_city, student_block, student_street, student_number, student_obs, class_id, resp_id) values('" + student.Student_name + "', '" + student.Student_ctr + "', 'Ativo', '" + student.Student_subscriptionDate + "', '" + student.Student_rg + "', '" + student.Student_cpf + "', '" + student.Student_birthDate + "', '" + student.Student_sex + "', '" + student.Student_phone + "', '" + student.Student_whatsApp + "', '" + student.Student_cep + "', '" + student.Student_state + "', '" + student.Student_city + "', '" + student.Student_block + "', '" + student.Student_street + "', '" + student.Student_number + "', '" + student.Student_obs + "', " + student.Class_id + ", " + resp.Resp_id + ");"; con = ConnectionFactory.Connection(); MySqlCommand cmd = new MySqlCommand(sql, con); con.Open(); cmd.ExecuteNonQuery(); con.Close(); string select = "select * from tbl_student where student_ctr = '" + student.Student_ctr + "';"; con.Open(); MySqlCommand cmdSelectStudent = new MySqlCommand(select, con); MySqlDataReader dtReaderSelect = cmdSelectStudent.ExecuteReader(); if (dtReaderSelect.Read()) { i = true; int v = 0; string select_vacancys = "select class_vacancys from tbl_class where class_id = " + student.Class_id + ";"; MySqlConnection conSelect = ConnectionFactory.Connection(); conSelect.Open(); MySqlCommand cmdSelect_Vacancys = new MySqlCommand(select_vacancys, conSelect); MySqlDataReader dtReaderVacancys = cmdSelect_Vacancys.ExecuteReader(); if (dtReaderVacancys.Read()) { v = dtReaderVacancys.GetInt16("class_vacancys"); } conSelect.Close(); string update = "update tbl_class set class_vacancys = " + (v - 1) + " where class_id = " + student.Class_id + ";"; conSelect.Open(); MySqlCommand cmdUpdate = new MySqlCommand(update, conSelect); cmdUpdate.ExecuteNonQuery(); conSelect.Close(); } else { i = false; } } else { string sql = @"insert into tbl_student(student_name, student_ctr, student_status, student_subscriptionDate, student_rg, student_cpf, student_birthDate, student_sex, student_phone, student_whatsApp, student_cep, student_state, student_city, student_block, student_street, student_number, student_obs, class_id, resp_id) values('" + student.Student_name + "', '" + student.Student_ctr + "', 'Ativo', '" + student.Student_subscriptionDate + "', '" + student.Student_rg + "', '" + student.Student_cpf + "', '" + student.Student_birthDate + "', '" + student.Student_sex + "', '" + student.Student_phone + "', '" + student.Student_whatsApp + "', '" + student.Student_cep + "', '" + student.Student_state + "', '" + student.Student_city + "', '" + student.Student_block + "', '" + student.Student_street + "', '" + student.Student_number + "', '" + student.Student_obs + "', " + student.Class_id + ", null);"; con = ConnectionFactory.Connection(); MySqlCommand cmd = new MySqlCommand(sql, con); con.Open(); cmd.ExecuteNonQuery(); con.Close(); string select = "select * from tbl_student where student_ctr = '" + student.Student_ctr + "';"; con.Open(); MySqlCommand cmdSelect = new MySqlCommand(select, con); MySqlDataReader dtReaderSelect = cmdSelect.ExecuteReader(); if (dtReaderSelect.Read()) { i = true; int v = 0; string select_vacancys = "select class_vacancys from tbl_class where class_id = " + student.Class_id + ";"; MySqlConnection conSelect = ConnectionFactory.Connection(); conSelect.Open(); MySqlCommand cmdSelect_Vacancys = new MySqlCommand(select_vacancys, conSelect); MySqlDataReader dtReaderVacancys = cmdSelect_Vacancys.ExecuteReader(); if (dtReaderVacancys.Read()) { v = dtReaderVacancys.GetInt16("class_vacancys"); } conSelect.Close(); string update = "update tbl_class set class_vacancys = " + (v - 1) + " where class_id = " + student.Class_id + ";"; conSelect.Open(); MySqlCommand cmdUpdate = new MySqlCommand(update, conSelect); cmdUpdate.ExecuteNonQuery(); conSelect.Close(); } else { i = false; } } } catch (MySqlException e) { throw new Exception(e.Message); } finally { con.Close(); } return(i); }
public bool DeleteStudent(string ctr) { bool i = false; TOStudent student = new TOStudent(); try { string sql = "delete from tbl_student where student_ctr = '" + ctr + "';"; string getClass_id = "select class_id from tbl_student where student_ctr = '" + ctr + "';"; con = ConnectionFactory.Connection(); con.Open(); MySqlCommand cmd = new MySqlCommand(getClass_id, con); MySqlDataReader reader = cmd.ExecuteReader(); reader.Read(); //verifying if class exists. var _classID = reader["class_id"] as int?; if (_classID.HasValue) { student.Class_id = reader.GetInt16("class_id"); con.Close(); con = ConnectionFactory.Connection(); con.Open(); MySqlCommand delete = new MySqlCommand(sql, con); delete.ExecuteNonQuery(); con.Close(); string select = "select * from tbl_student where student_ctr = '" + ctr + "';"; con.Open(); MySqlCommand command = new MySqlCommand(select, con); MySqlDataReader dtreader = command.ExecuteReader(); if (dtreader.Read())//If there's any data. { i = false; } else { i = true; } con.Close(); if (i == true) { int v = 0; string getVacancys = "select class_vacancys from tbl_class where class_id = " + student.Class_id + ";"; con = ConnectionFactory.Connection(); con.Open(); MySqlCommand Vacancys = new MySqlCommand(getVacancys, con); MySqlDataReader get = Vacancys.ExecuteReader(); if (get.Read()) { v = get.GetInt16("class_vacancys"); int total = v + 1; string newVacancy = "update tbl_class set class_vacancys = " + total + " where class_id = " + student.Class_id + ";"; MySqlConnection connection = ConnectionFactory.Connection(); connection.Open(); MySqlCommand _newVacancy = new MySqlCommand(newVacancy, connection); _newVacancy.ExecuteNonQuery(); connection.Close(); } } con.Close(); } else { con = ConnectionFactory.Connection(); con.Open(); MySqlCommand delete = new MySqlCommand(sql, con); delete.ExecuteNonQuery(); i = true; } } catch (MySqlException e) { throw new Exception(e.Message); } finally { con.Close(); } return(i); }
public TOStudent Selection(string ctr) { MySqlConnection con = null; TOStudent i = new TOStudent(); try { string sql = "select * from tbl_student where student_ctr = '" + ctr + "';"; con = ConnectionFactory.Connection(); MySqlCommand cmd = new MySqlCommand(sql, con); con.Open(); MySqlDataReader dtreader = cmd.ExecuteReader(); if (dtreader.Read())//If there's any data. { var _classID = dtreader["class_id"] as int?; if (_classID.HasValue) { i.Class_id = dtreader.GetInt16("class_id"); } else { i.Resp_id = 0; } i.Student_id = dtreader.GetInt16("student_id"); i.Student_birthDate = dtreader.GetString("student_birthDate"); i.Student_block = dtreader.GetString("student_block"); i.Student_cep = dtreader.GetString("student_cep"); i.Student_city = dtreader.GetString("student_city"); i.Student_cpf = dtreader.GetString("student_cpf").ToString(); i.Student_name = dtreader.GetString("student_name"); i.Student_number = dtreader.GetString("student_number"); i.Student_obs = dtreader.GetString("student_obs"); i.Student_phone = dtreader.GetString("student_phone"); i.Student_rg = dtreader.GetString("student_rg"); i.Student_sex = dtreader.GetString("student_sex"); i.Student_state = dtreader.GetString("student_state"); i.Student_street = dtreader.GetString("student_street"); i.Student_whatsApp = dtreader.GetString("student_whatsApp"); i.Student_ctr = dtreader.GetString("student_ctr"); i.Student_subscriptionDate = dtreader.GetString("student_subscriptionDate"); var _respID = dtreader["resp_id"] as int?; if (_respID.HasValue) { i.Resp_id = dtreader.GetInt16("resp_id"); } else { i.Resp_id = 0; } } else { } } catch (MySqlException e) { throw new Exception(e.Message); } finally { con.Close(); } return(i); }
public bool Update(TOStudent student, TOResponsable resp) { bool i = false; TOClass _class = new TOClass(); try { if (resp != null) { string sql = @"update tbl_student set student_name = '" + student.Student_name + "', student_ctr = '" + student.Student_ctr + "', student_status = '" + student.Student_state + "', student_rg = '" + student.Student_rg + "', student_cpf = '" + student.Student_cpf + "', student_birthDate = '" + student.Student_birthDate + "', student_sex = '" + student.Student_sex + "', student_phone = '" + student.Student_phone + "', student_whatsApp = '" + student.Student_whatsApp + "', student_cep = '" + student.Student_cep + "', student_state = '" + student.Student_state + "', student_city = '" + student.Student_city + "', student_block = '" + student.Student_block + "', student_street = '" + student.Student_street + "', student_number = '" + student.Student_number + "', student_obs = '" + student.Student_obs + "', class_id = " + student.Class_id + ", resp_id = " + student.Resp_id + " where student_id = " + student.Student_id + ";"; con = ConnectionFactory.Connection(); MySqlCommand cmd = new MySqlCommand(sql, con); con.Open(); cmd.ExecuteNonQuery(); con.Close(); string select = "select * from tbl_student where student_ctr = '" + student.Student_ctr + "';"; con.Open(); MySqlCommand cmdSelectStudent = new MySqlCommand(select, con); MySqlDataReader dtReaderSelect = cmdSelectStudent.ExecuteReader(); if (dtReaderSelect.Read()) { i = true; } else { i = false; } con.Close(); string update_resp = @"update tbl_resp set resp_name = '" + resp.Resp_name + "', resp_rg = '" + resp.Resp_rg + "', resp_cpf = '" + resp.Resp_cpf + "', resp_birthDate = '" + resp.Resp_birthDate + "', resp_sex = '" + resp.Resp_sex + "', resp_phone = '" + resp.Resp_phone + "', resp_whatsApp = '" + resp.Resp_whatsApp + "', resp_cep = '" + resp.Resp_cep + "', resp_state = '" + resp.Resp_state + "', resp_city = '" + resp.Resp_city + "', resp_block = '" + resp.Resp_block + "', resp_street = '" + resp.Resp_street + "', resp_number = '" + resp.Resp_number + "', resp_obs = '" + resp.Resp_obs + "' where resp_id = " + resp.Resp_id + ";"; con = ConnectionFactory.Connection(); MySqlCommand cmdUpdateResp = new MySqlCommand(update_resp, con); con.Open(); cmdUpdateResp.ExecuteNonQuery(); } else { string sql = @"update tbl_student set student_name = '" + student.Student_name + "', student_ctr = '" + student.Student_ctr + "', student_status = '" + student.Student_state + "', student_subscriptionDate = '" + student.Student_subscriptionDate + "', student_rg = '" + student.Student_rg + "', student_cpf = '" + student.Student_cpf + "', student_birthDate = '" + student.Student_birthDate + "', student_sex = '" + student.Student_sex + "', student_phone = '" + student.Student_phone + "', student_whatsApp = '" + student.Student_whatsApp + "', student_cep = '" + student.Student_cep + "', student_state = '" + student.Student_state + "', student_city = '" + student.Student_city + "', student_block = '" + student.Student_block + "', student_street = '" + student.Student_street + "', student_number = '" + student.Student_number + "', student_obs = '" + student.Student_obs + "', class_id = " + student.Class_id + ", resp_id = null where student_id = " + student.Resp_id + ";"; con = ConnectionFactory.Connection(); MySqlCommand cmd = new MySqlCommand(sql, con); con.Open(); cmd.ExecuteNonQuery(); con.Close(); string select = "select * from tbl_student where student_ctr = '" + student.Student_ctr + "';"; con.Open(); MySqlCommand cmdSelect = new MySqlCommand(select, con); MySqlDataReader dtReaderSelect = cmdSelect.ExecuteReader(); if (dtReaderSelect.Read()) { i = true; } else { i = false; } } } catch (MySqlException e) { throw new Exception(e.Message); } finally { con.Close(); } return(i); }
public REG_student(TOStudent student) { InitializeComponent(); op = 1; btnRegisterStudent.Content = "Editar"; _student = student; txtName.Text = _student.Student_name; txtRG.Text = _student.Student_rg; txtCPF.Text = _student.Student_cpf; if (_student.Student_birthDate != String.Empty) { birthDate.SelectedDate = DateTime.Parse(_student.Student_birthDate); } else { } txtPhone.Text = _student.Student_phone; txtWhatsApp.Text = _student.Student_whatsApp; txtCEP.Text = _student.Student_cep; txtState.Text = _student.Student_state; txtCity.Text = _student.Student_city; txtBlock.Text = _student.Student_block; txtNumber.Text = _student.Student_number; txtAdd.Text = _student.Student_obs; txtCtr.Text = _student.Student_ctr; txtStreet.Text = _student.Student_street; if (_student.Student_sex == "Feminino") { cbxSex.SelectedIndex = 0; } else if (_student.Student_sex == "Masculino") { cbxSex.SelectedIndex = 1; } DateTime _birth = DateTime.Parse(_student.Student_birthDate); int age = (int)Math.Floor((DateTime.Now - _birth).TotalDays / 365.25D); if (age >= 18) { _resp = null; } else { DAOStudents dao = new DAOStudents(); TOResponsable r = new TOResponsable(); r = dao.SelectResp(_student.Resp_id); _resp = r; txtName_resp.Text = r.Resp_name; txtRG_resp.Text = r.Resp_rg; txtCPF_resp.Text = r.Resp_cpf; if (r.Resp_birthDate != String.Empty) { birthDate_resp.SelectedDate = DateTime.Parse(r.Resp_birthDate); } else { } if (_resp.Resp_cep == _student.Student_cep && _resp.Resp_number == _student.Student_number || _resp.Resp_street == _student.Student_street && _resp.Resp_number == _student.Student_number) { checkBox_sameAdress.IsChecked = true; } else { checkBox_sameAdress.IsChecked = false; } txtPhone_resp.Text = r.Resp_phone; txtWhatsApp_resp.Text = r.Resp_whatsApp; txtCEP_resp.Text = r.Resp_cep; txtState_resp.Text = r.Resp_state; txtCity_resp.Text = r.Resp_city; txtBlock_resp.Text = r.Resp_block; txtNumber_resp.Text = r.Resp_number; txtAdd_resp.Text = r.Resp_obs; txtStreet_resp.Text = r.Resp_street; if (r.Resp_sex == "Feminino") { cbxSex_resp.SelectedIndex = 0; } else if (r.Resp_sex == "Masculino") { cbxSex_resp.SelectedIndex = 1; } } //loads the table. DAOClass _class = new DAOClass(); tblClass.CanUserAddRows = false; tblClass.IsReadOnly = true; tblClass.AutoGenerateColumns = false; List <TOClass> c = new List <TOClass>(); c = _class.LoadClass(_student.Class_id); foreach (TOClass _c in c) { if (_c.Type == "Hardware") { rdbtn_hard.IsChecked = true; } else if (_c.Type == "Informática") { rdbtn_info.IsChecked = true; } else if (_c.Type == "Inglês") { rdbtn_en.IsChecked = true; } else if (_c.Type == "Administração") { rdbtn_adm.IsChecked = true; } else if (_c.Type == "Interativo") { rdbtn_int.IsChecked = true; } else if (_c.Type == "Game") { rdbtn_game.IsChecked = true; } } tblClass.ItemsSource = _class.LoadClass(_student.Class_id); tabClass_Grid.IsEnabled = false; tabStudent_Grid.IsEnabled = false; tabParent_Grid.IsEnabled = false; txtCtr.IsEnabled = false; }