예제 #1
0
        // 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();
            }
        }
예제 #2
0
        // 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 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 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();
            }
        }
예제 #6
0
        // 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();
            }
        }
 public void listBoxCentroAlterada()
 {
     if (myForm.listBox1.SelectedIndex > -1)
     {
         myForm.centroAtual = myForm.listBox1.SelectedIndex + 1;
         funcoesAux.clearAllListBox();
         ClearItems();
         HideAll();
         funcoesAux.HideButtons();
         ResetAll();
         MostrarCentro();
         BtnVisibles();
         ShowEditRemBtn();
         funcoesAux.UnlockButtons();
     }
 }
예제 #8
0
        // CONFIRMAR
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (addOrEdit == 0)
            {
                if (lastButton == 1)
                {
                    funcoesLojas.AddLoja();
                }
                else if (lastButton == 2)
                {
                    funcoesDepartamentos.AddDepartamento();
                }
                else if (lastButton == 3)
                {
                    funcoesPrestadores.AddPrestadores();
                }
                else if (lastButton == 4)
                {
                    funcoesEmpresas.AddEmpresa();
                }
                else if (lastButton == 5)
                {
                    funcoesEventos.AddEvento();
                }
                else if (lastButton == 6)
                {
                    funcoesFuncionarios.AddFuncionarios();
                }
                else if (lastButton == 7)
                {
                    funcoesResp_dep.AddResponsavel();
                }
            }
            else if (addOrEdit == 1)
            {
                if (lastButton == 1)
                {
                    funcoesLojas.EditLoja();
                }
                else if (lastButton == 2)
                {
                    funcoesDepartamentos.EditDepartamento();
                }
                else if (lastButton == 3)
                {
                    funcoesPrestadores.EditPrestadores();
                }
                else if (lastButton == 4)
                {
                    funcoesEmpresas.EditEmpresa();
                }
                else if (lastButton == 5)
                {
                    funcoesEventos.EditEvento();
                }
                else if (lastButton == 6)
                {
                    funcoesFuncionarios.EditFuncionarios();
                }
                else if (lastButton == 7)
                {
                    funcoesResp_dep.EditResponsavel();
                }
            }
            else if (addOrEdit == 2)
            {
                if (lastButton == 1)
                {
                    funcoesLojas.SearchLoja();
                }
                else if (lastButton == 2)
                {
                    funcoesDepartamentos.SearchDepartamento();
                }
                else if (lastButton == 3)
                {
                    funcoesPrestadores.SearchPrestador();
                }
                else if (lastButton == 4)
                {
                    funcoesEmpresas.SearchEmpresa();
                }
                else if (lastButton == 5)
                {
                    funcoesEventos.SearchEvento();
                }
                else if (lastButton == 6)
                {
                    funcoesFuncionarios.SearchFuncionarios();
                }
                else if (lastButton == 7)
                {
                    funcoesResp_dep.SearchResponsavel();
                }
            }
            else if (addOrEdit == 3)
            {
                if (lastButton == 1)
                {
                    funcoesLojas.RemoveLoja();
                }
                else if (lastButton == 2)
                {
                    funcoesDepartamentos.RemoveDepartamento(((Departamento)listBox3.SelectedItem).ID);
                }
                else if (lastButton == 3)
                {
                    funcoesPrestadores.RemovePrestadores();
                }
                else if (lastButton == 4)
                {
                    funcoesEmpresas.RemoveEmpresa(((Empresa)listBox5.SelectedItem).NIF);
                }
                else if (lastButton == 5)
                {
                    funcoesEventos.RemoveEvento();
                }
                else if (lastButton == 6)
                {
                    funcoesFuncionarios.RemoveFuncionarios();
                }
                else if (lastButton == 7)
                {
                    funcoesResp_dep.RemoveResponsavel();
                }
            }

            funcoesAux.UnlockButtons();
            funcoesAux.EnableListBox();
            funcoesAux.ReadOnly();
            funcoesAux.CancelConfirm(lastButton);
            funcoesAux.ShowAddBtn();

            if (lastButton == 1 || lastButton == 4)
            {
                CN.Open();
                SqlCommand cmd = new SqlCommand("SELECT dbo.fnGetNumLojas(@ID_centro)", CN);
                cmd.Parameters.AddWithValue("@ID_centro", textCentroID.Text);
                textCentroNumeroLojas.Text = cmd.ExecuteScalar().ToString();
                CN.Close();
            }
        }