// Remover prestadores public void RemovePrestadores() { myForm.CN.Open(); string nif = (((Prestador2)myForm.listBox4.SelectedItem).NIF); // chave primaria SqlCommand cmd = new SqlCommand(); cmd.CommandText = "DELETE centro_comercial.prestador WHERE NIF=@NIF"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@NIF", nif); cmd.Connection = myForm.CN; try { RemoveInterage(nif); cmd.ExecuteNonQuery(); myForm.listBox4.Items.Remove((Prestador2)myForm.listBox4.SelectedItem); funcoesAux.UnlockButtons(); funcoesAux.ClearFields(); funcoesAux.EnableListBox(); funcoesAux.ReadOnly(); funcoesAux.ShowButtons(); } catch (Exception ex) { MessageBox.Show("ERRO: " + ex.Message); } finally { myForm.CN.Close(); } }
// Remover funcionarios public void RemoveFuncionarios() { myForm.CN.Open(); string nif = (((Funcionario)myForm.listBox7.SelectedItem).NIF); // chave primaria SqlCommand cmd = new SqlCommand(); cmd.CommandText = "BEGIN TRANSACTION; DELETE centro_comercial.funcionario_loja WHERE NIF = @NIF; " + "DELETE centro_comercial.pessoa WHERE NIF = @NIF; COMMIT;"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@NIF", nif); cmd.Connection = myForm.CN; try { cmd.ExecuteNonQuery(); myForm.listBox7.Items.Remove((Funcionario)myForm.listBox7.SelectedItem); funcoesAux.UnlockButtons(); funcoesAux.ClearFields(); funcoesAux.EnableListBox(); funcoesAux.ReadOnly(); funcoesAux.ShowButtons(); } catch (Exception ex) { MessageBox.Show("Não é possível remover funcionário" + ex.Message); } finally { myForm.CN.Close(); } }
// Remover loja public void RemoveLoja() { myForm.CN.Open(); string num = (((Loja)myForm.listBox2.SelectedItem).Num_loja); // chave primaria SqlCommand cmd = new SqlCommand(); cmd.CommandText = "DELETE centro_comercial.loja WHERE Num_loja=@Num_loja;"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@Num_loja", num); cmd.Connection = myForm.CN; try { RemoveFuncionariosLojas(num); cmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show("ERRO: " + ex.Message); } finally { myForm.CN.Close(); getTabelaLojas(); MostrarLoja(); funcoesAux.ClearFields(); } }
// Remover evento public void RemoveEvento() { myForm.CN.Open(); string nome = (((Evento)myForm.listBox6.SelectedItem).Nome); // chave primaria SqlCommand cmd = new SqlCommand(); cmd.CommandText = "DELETE centro_comercial.eventos WHERE Nome=@Nome"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@Nome", nome); cmd.Connection = myForm.CN; try { cmd.ExecuteNonQuery(); myForm.listBox6.Items.Remove((Evento)myForm.listBox6.SelectedItem); funcoesAux.UnlockButtons(); funcoesAux.ClearFields(); funcoesAux.EnableListBox(); funcoesAux.ReadOnly(); funcoesAux.ShowButtons(); } catch (Exception ex) { MessageBox.Show("ERRO: " + ex.Message); } finally { myForm.CN.Close(); } }
// Remover empresa public void RemoveEmpresa(string nif) { myForm.CN.Open(); SqlCommand cmd = new SqlCommand("spDelLojasEmpresa", myForm.CN); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@NIF_empresa", nif)); cmd.Parameters.Add(new SqlParameter("@ID_centro", myForm.textCentroID.Text)); try { cmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show("ERRO: " + ex.Message); } finally { myForm.CN.Close(); getTabelaEmpresas(); MostrarEmpresa(); funcoesAux.UnlockButtons(); funcoesAux.ClearFields(); funcoesAux.ReadOnly(); funcoesAux.ShowAddBtn(); } }
// Remover funcionarios public void RemoveResponsavel() { myForm.CN.Open(); string nif = (((Resp_departamento)myForm.listBox8.SelectedItem).NIF); // chave primaria SqlCommand cmd = new SqlCommand(); cmd.CommandText = "BEGIN TRANSACTION; DELETE centro_comercial.responsavel_departamento WHERE NIF = @NIF; " + "DELETE centro_comercial.pessoa WHERE NIF = @NIF; COMMIT;"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@NIF", nif); cmd.Connection = myForm.CN; try { cmd.ExecuteNonQuery(); myForm.listBox8.Items.Remove((Resp_departamento)myForm.listBox8.SelectedItem); funcoesAux.UnlockButtons(); funcoesAux.ClearFields(); funcoesAux.EnableListBox(); funcoesAux.ReadOnly(); funcoesAux.ShowButtons(); } catch (Exception) { MessageBox.Show("Impossivel remover responsavel pois este está encarregue de um departamento"); } finally { myForm.CN.Close(); } }
// Remover departamento public void RemoveDepartamento(string id) { myForm.CN.Open(); SqlCommand cmd = new SqlCommand("spDelDepartamento", myForm.CN); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@ID_centro", myForm.textCentroID.Text)); cmd.Parameters.Add(new SqlParameter("@ID_departamento", id)); try { cmd.ExecuteNonQuery(); } catch (Exception) { MessageBox.Show("Não pode remover nenhum dos 3 departamentos essenciais (marketing, comercial, operaçoes).\n"); } finally { myForm.CN.Close(); getTabelaDepartamentos(); MostrarDepartamento(); funcoesAux.UnlockButtons(); funcoesAux.ClearFields(); funcoesAux.ReadOnly(); funcoesAux.ShowAddBtn(); } }
// Remove centro public void RemoveCentro() { myForm.CN.Open(); string id = (((Centro)myForm.listBox1.SelectedItem).ID); SqlCommand cmd = new SqlCommand("spDelCentro", myForm.CN); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@ID_centro", id)); try { cmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show("ERRO: " + ex.Message); } finally { myForm.CN.Close(); getTabelaCentros(); MostrarCentro(); funcoesAux.UnlockButtons(); funcoesAux.ClearFields(); funcoesAux.ReadOnly(); funcoesAux.ShowAddBtn(); } }
// ADICIONAR private void btnAdd_Click(object sender, EventArgs e) { addOrEdit = 0; funcoesAux.ClearFields(); funcoesAux.ShowConfCancButtons(); funcoesAux.DisableListBox(); funcoesAux.LockButtons(); funcoesAux.EnableWrite(); funcoesAux.Add(lastButton); funcoesLojas.setComboBoxEmpresas(); funcoesFuncionarios.setComboBoxLojas(); if (lastButton == 2) { departamentos1.setNumDep(funcoesDepartamentos.getNumDep()); } else if (lastButton == 1) { lojas1.setNumLoja(funcoesLojas.getNumLoja()); lojas1.setTextNumLoja(lojas1.getNumLoja().ToString()); } }