コード例 #1
0
ファイル: ListStx.cs プロジェクト: brunostrik/STX
 private void btnImprimir_Click(object sender, EventArgs e)
 {
     Alerts.Error("Funcionalidade ainda nao implementada");
 }
コード例 #2
0
ファイル: FormStx.cs プロジェクト: brunostrik/STX
        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);
        }