示例#1
0
        private void AtivarDesativar_Setor_Click(object sender, EventArgs e)
        {
            //--- verifica se existe alguma cell
            if (dgvListagem.SelectedRows.Count == 0)
            {
                return;
            }

            //--- Verifica o item
            objSetor setor = (objSetor)dgvListagem.SelectedRows[0].DataBoundItem;

            //--- check saldo existente
            if (setor.SetorSaldo > 0)
            {
                AbrirDialog("Não é possivel desastivar um setor que possui SALDO...",
                            "Saldo Existente", DialogType.OK, DialogIcon.Exclamation);
                return;
            }

            //---pergunta ao usuário
            var reponse = AbrirDialog($"Deseja realmente {(setor.Ativa ? "DESATIVAR " : "ATIVAR")} esse Setor?\n" +
                                      setor.Setor.ToUpper(), (setor.Ativa ? "DESATIVAR " : "ATIVAR"),
                                      DialogType.SIM_NAO, DialogIcon.Question);

            if (reponse == DialogResult.No)
            {
                return;
            }

            //--- altera o valor
            setor.Ativa = !setor.Ativa;

            //--- Salvar o Registro
            try
            {
                // --- Ampulheta ON
                Cursor.Current = Cursors.WaitCursor;

                SetorBLL cBLL = new SetorBLL();
                cBLL.UpdateSetor(setor);

                //--- altera a imagem
                ObterDados(null, null);
                FiltrarListagem(sender, e);
            }
            catch (Exception ex)
            {
                AbrirDialog("Uma exceção ocorreu ao Alterar Setor..." + "\n" +
                            ex.Message, "Exceção", DialogType.OK, DialogIcon.Exclamation);
            }
            finally
            {
                // --- Ampulheta OFF
                Cursor.Current = Cursors.Default;
            }
        }
        // SALVAR REGISTRO
        //------------------------------------------------------------------------------------------------------------
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            try
            {
                // --- Ampulheta ON
                Cursor.Current = Cursors.WaitCursor;

                //--- check data
                if (!CheckSaveData())
                {
                    return;
                }

                SetorBLL sBLL = new SetorBLL();

                //--- SAVE: INSERT OR UPDATE
                if (_setor.IDSetor == null)                 //--- save | Insert
                {
                    int ID = sBLL.InsertSetor(_setor);
                    //--- define newID
                    _setor.IDSetor = ID;
                }
                else                 //--- update
                {
                    sBLL.UpdateSetor(_setor);
                }

                //--- change Sit
                Sit = EnumFlagEstado.RegistroSalvo;
                //--- emit massage
                AbrirDialog("Registro Salvo com sucesso!",
                            "Registro Salvo", DialogType.OK, DialogIcon.Information);
            }
            catch (Exception ex)
            {
                AbrirDialog("Uma exceção ocorreu ao Salvar Registro de Setor..." + "\n" +
                            ex.Message, "Exceção", DialogType.OK, DialogIcon.Exclamation);
            }
            finally
            {
                // --- Ampulheta OFF
                Cursor.Current = Cursors.Default;
            }
        }