Beispiel #1
0
 private bool ValidarMontarPreenchimento()
 {
     if (string.IsNullOrWhiteSpace(txtCodigo.Text))
     {
         Alerts.Alert("O preenchimento do campo é obrigatório: " + "Código");
         txtCodigo.Focus();
         return(false);
     }
     if (string.IsNullOrWhiteSpace(txtNome.Text))
     {
         Alerts.Alert("O preenchimento do campo é obrigatório: " + "Nome");
         txtNome.Focus();
         return(false);
     }
     if (cmbAtivo.SelectedIndex == 0)
     {
         if (!Alerts.Ask("Tem certeza que deseja definir este item como desativado?\nUm item desativado não aparecerá como disponível no sistema, embora continue existindo para consultas e relatórios antigos."))
         {
             cmbAtivo.Focus();
             return(false);
         }
     }
     //Montar entidade
     entity.id    = Convert.ToInt32(txtCodigo.Text);
     entity.nome  = txtNome.Text;
     entity.ativo = cmbAtivo.SelectedIndex == 0;
     return(true);
 }
Beispiel #2
0
 private void btnExcluir_Click(object sender, EventArgs e)
 {
     if (!Alerts.Ask("Confirma a exclusão do item selecionado?"))
     {
         return;
     }
     ExcluirPressed(sender, e);
 }
Beispiel #3
0
        private void ExcluirSelecionado()
        {
            if (!Alerts.Ask("Confirma a exclusão do item selecionado?"))
            {
                return;
            }

            itemSelecionado.Delete();
            Alerts.Message("Item excluído!");
            btnAtualizar_Click(null, null);
        }
Beispiel #4
0
        private void ExcluirSelecionado()
        {
            if (!Alerts.Ask("Confirma a exclusão do item selecionado?"))
            {
                return;
            }

            if (itemSelecionado.Delete())
            {
                Alerts.Message("Item excluído!");
                AtualizarDados();
            }
            else
            {
                Alerts.Error("Falha ao excluir o item selecionado.");
            }
        }
Beispiel #5
0
        private void Excluir()
        {
            if (!Alerts.Ask("Confirma a exclusão do item selecionado?"))
            {
                return;
            }

            if (entity.Delete())
            {
                Alerts.Message("Item excluído!");
                if (listaRetorno != null)
                {
                    listaRetorno.Retornar();
                }
                Close();
            }
            else
            {
                Alerts.Error("Falha ao excluir este item.");
            }
        }
Beispiel #6
0
        private bool ConfigureDatabaseSystem()
        {
            switch (DBConfig.TestDatabaseConnection())
            {
            case 0:     //tudo certo
                return(true);

            case 1:     //sem arquivo de configuração
                if (Alerts.Ask("O sistema não encontrou o arquivo de configuração.\rDeseja selecionar o arquivo agora?"))
                {
                    OpenFileDialog ofd = new OpenFileDialog();
                    ofd.DefaultExt  = "cfg";
                    ofd.Filter      = "Arquivo de configuração (*.cfg)|*.cfg";
                    ofd.Multiselect = false;
                    if (ofd.ShowDialog() == DialogResult.OK)
                    {
                        DBConfig.SaveConfigFile(ofd.FileName);
                        return(ConfigureDatabaseSystem());
                    }
                    else
                    {
                        return(ConfigureDatabaseSystem());
                    }
                }
                else
                {
                    Application.Exit();
                    return(false);
                }

            case 2:     //rede cagada
                Alerts.Error("Não foi possível conectar ao servidor de banco de dados. Provavelmente há um problema de conexão de rede/internet.\rVerifique sua conexão de internet, se estiver funcionando entre em contato com a " + Config.EMPRESA_MANTENEDORA + " pelo telefone " + Config.TELEFONE_SUPORTE);
                Application.Exit();
                return(false);

            default:
                Application.Exit();
                return(false);
            }
        }
Beispiel #7
0
        private bool ValidarMontarPreenchimento()
        {
            //identificar os controles e pegar os valores
            foreach (Control control in tableLayoutPanel.Controls)
            {
                if (control.GetType() == typeof(Label)) //pula as labels
                {
                    continue;
                }
                string tipoControle = control.Name.Substring(0, 3);
                string nomeControle = control.Name.Substring(3);
                var    props        = typeof(T).GetProperties();
                foreach (var prop in props)
                {
                    if (prop.Name == nomeControle)
                    {
                        //analisa se é de preenchimento obrigatório
                        foreach (var a in prop.GetCustomAttributes(false))
                        {
                            if (a.GetType() == typeof(RequiredAttribute)) //é obrigatorio
                            {
                                if (string.IsNullOrWhiteSpace(control.Text))
                                {
                                    Alerts.Alert(((RequiredAttribute)a).ErrorMessage);
                                    control.Focus();
                                    return(false);
                                }
                            }
                        }
                        switch (tipoControle)//preenche o valor na entidade
                        {
                        case "txt":
                            prop.SetValue(entity, control.Text);
                            break;

                        case "csn":
                            if (nomeControle.ToLower() == "ativo")
                            {
                                //perguntar se o cara tem certeza que quer desativar, se o falor for 0
                                if (!((ComboBoxSimNao)control).Value)
                                {
                                    if (!Alerts.Ask("Ao este item como não ativo, ele não será mais mostrado no sistema. Você tem certeza disso?"))
                                    {
                                        return(false);
                                    }
                                }
                            }
                            prop.SetValue(entity, ((ComboBoxSimNao)control).Value);
                            break;

                        case "tbn":
                            prop.SetValue(entity, ((TextBoxNumber)control).Value);
                            break;

                        case "tbd":
                            prop.SetValue(entity, ((TextBoxDecimal)control).Value);
                            break;

                        case "dtp":
                            if (((DateTimePicker)control).Value == null)
                            {
                                Alerts.Alert("Por favor selecione uma data válida");
                                control.Focus();
                                return(false);
                            }
                            prop.SetValue(entity, ((DateTimePicker)control).Value);
                            break;

                        default:
                            prop.SetValue(entity, control.Text);
                            break;
                        }
                    }
                }
            }
            return(true);
        }