Beispiel #1
0
        /// <summary>
        /// Valida todos os campos do formulario.
        /// </summary>
        /// <param name="controle">Passa a coleção de controles do formulário</param>
        /// <returns>Retorna se os campos estão validos ou não (true/false)</returns>
        internal bool ValidarCampos(Control.ControlCollection controle)
        {
            Boolean bRetorno = true;

            foreach (Control ctrl in controle)
            {
                //-- Caso o controle possua mais controles internos.
                if (ctrl.Controls.Count > 0 && ctrl.GetType() != typeof(cf_Bases.cf_DateEdit))
                {
                    //-- Chama o mesmo método para obter os controles.
                    //-- Este processo utiliza recurcividade.
                    bool sTempRet = this.ValidarCampos(ctrl.Controls);
                    if (bRetorno && !sTempRet)
                    {
                        bRetorno = false;
                    }
                }
                else
                {
                    if (ctrl.GetType().GetInterface("IBaseControl_DB", true) != null)
                    {
                        Interfaces.IBaseControl_DB cc = ctrl as Interfaces.IBaseControl_DB;
                        if (!cc.ValidarCampos())
                        {
                            if (bRetorno)
                            {
                                bRetorno = false;
                            }
                        }
                    }
                }
            }
            return(bRetorno);
        }
Beispiel #2
0
        /// <summary>
        /// Retorna se o controle está associado a uma coluna Identity
        /// </summary>
        /// <param name="ctrl">controle já customizado (Class CustonControl)</param>
        /// <returns>true/false se o controle é Identity</returns>
        private bool Control_IsIdentity(ref Interfaces.IBaseControl_DB ctrl)
        {
            bool bRetono = false;

            if (Propriedades.FormMain != null && Propriedades.FormMain.ActiveMdiChild != null)
            {
                FormSet f = (FormSet)Propriedades.FormMain.ActiveMdiChild;

                if (ctrl.Tabela == f.MainTabela && !string.IsNullOrEmpty(ctrl.ControlSource))
                {
                    DataColumn dc = f.DataSetLocal.Tables[ctrl.Tabela].Columns[ctrl.ControlSource];
                    bRetono = dc.AutoIncrement;
                }
            }

            return(bRetono);
        }
Beispiel #3
0
        /// <summary>
        /// Limpa tabela de acordo com parametros.
        /// </summary>
        /// <param name="cc">Coleção de controles</param>
        internal void Limpa_Campos(Control.ControlCollection cc, string sTabela)
        {
            for (int i = 0; i < cc.Count; i++)
            {
                if (cc[i].Controls.Count > 0)
                {
                    this.Limpa_Campos(cc[i].Controls, sTabela);
                }
                else
                {
                    if (cc[i].GetType().GetInterface("IBaseControl_DB", true) != null)
                    {
                        Interfaces.IBaseControl_DB cc1 = (Interfaces.IBaseControl_DB)cc[i];
                        if (cc1.Tabela.ToLower().Equals(sTabela.ToLower()))
                        {
                            switch (cc[i].GetType().Name)
                            {
                            case "cf_TextBox":
                            case "cf_MaskedBox":
                                ((Interfaces.IBaseControl_DB_Generic <string>)cc[i]).Value = string.Empty;
                                break;

                            case "cf_DateEdit":
                                ((Interfaces.IBaseControl_DB_Generic <DateTime?>)cc[i]).Value = null;
                                break;

                            case "cf_ComboBox":
                                ((Interfaces.IBaseControl_DB_Generic <object>)cc[i]).Value = DBNull.Value;
                                break;

                            case "cf_CheckBox":
                            case "cf_RadioButton":
                                ((Interfaces.IBaseControl_DB_Generic <bool>)cc[i]).Value = false;
                                break;
                            }
                        }
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Metodo que retorna a clausula WHERE com todos os campos preenchidos do formulário.
        /// </summary>
        /// <param name="controle">Coleção pai de todos os controles do form (Formulario.Controls)</param>
        internal void get_QueryBy(Control.ControlCollection controle, string sMainTabela)
        {
            foreach (Control ctrl in controle)
            {
                //-- Caso o controle possua mais controles internos.
                if (ctrl.Controls.Count > 0 && ctrl.GetType() != typeof(cf_DateEdit))
                {
                    //-- Chama o mesmo método para obter os controles.
                    //-- Este processo utiliza recursividade.
                    get_QueryBy(ctrl.Controls, sMainTabela);
                }
                else
                {
                    try
                    {
                        if (ctrl.GetType().GetInterface("IBaseControl_DB", true) != null)
                        {
                            Interfaces.IBaseControl_DB cc = (Interfaces.IBaseControl_DB)ctrl;
                            if (cc.Incluir_QueryBy && cc.Tabela.Equals(sMainTabela) && !string.IsNullOrEmpty(cc.ValueQueryBy))
                            {
                                //-- Verifica se inclui no queryby
                                switch (ctrl.GetType().Name)
                                {
                                case "cf_TextBox":
                                    //-- Inclui o AND para tratar os dados.
                                    if (sbCondicao.Length > 0)
                                    {
                                        sbCondicao.Append(" AND ");
                                    }
                                    else
                                    {
                                        sbCondicao.Append(" ");
                                    }

                                    sbCondicao.Append(cc.Tabela_INNER);
                                    sbCondicao.Append(".");
                                    sbCondicao.Append(cc.ControlSource);

                                    switch (((Interfaces.ITextControl_DB)cc).TipoControles)
                                    {
                                    case CompSoft.TipoControle.Texto:
                                    case CompSoft.TipoControle.Geral:
                                        sbCondicao.Append(" like '");
                                        sbCondicao.Append(cc.ValueQueryBy);
                                        sbCondicao.Append("' ");
                                        break;

                                    case CompSoft.TipoControle.Indice:
                                    case CompSoft.TipoControle.Inteiro:
                                    case CompSoft.TipoControle.Moeda:
                                    case CompSoft.TipoControle.Numerico:
                                        sbCondicao.Append(" = ");
                                        sbCondicao.Append(cc.ValueQueryBy);
                                        break;

                                    default:
                                        sbCondicao.Append(" = '");
                                        sbCondicao.Append(cc.ValueQueryBy);
                                        sbCondicao.Append("' ");
                                        break;
                                    }
                                    break;

                                case "cf_DateEdit":
                                    if (sbCondicao.Length > 0)
                                    {
                                        sbCondicao.Append(" AND ");
                                    }

                                    sbCondicao.Append(" convert(datetime, convert(varchar(10), ");
                                    sbCondicao.Append(cc.Tabela_INNER);
                                    sbCondicao.Append(".");
                                    sbCondicao.Append(cc.ControlSource);
                                    sbCondicao.Append(", 112)) = '");
                                    sbCondicao.Append(cc.ValueQueryBy);
                                    sbCondicao.Append("' ");
                                    break;

                                default:
                                    //-- Inclui o AND para tratar os dados.
                                    if (sbCondicao.Length > 0)
                                    {
                                        sbCondicao.Append(" AND ");
                                    }
                                    else
                                    {
                                        sbCondicao.Append(" ");
                                    }

                                    sbCondicao.Append(cc.Tabela_INNER);
                                    sbCondicao.Append(".");
                                    sbCondicao.Append(cc.ControlSource);
                                    sbCondicao.Append(" like '");
                                    sbCondicao.Append(cc.ValueQueryBy);
                                    sbCondicao.Append("' ");

                                    break;
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MsgBox.Show("Erro ao executar QueryBy\r\n" + ctrl.Name + "\r\n" + ex.Message
                                    , "Atenção"
                                    , MessageBoxButtons.OK
                                    , MessageBoxIcon.Error);
                    }
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Seta todos os DataBind do formulário.
        /// </summary>
        /// <param name="controle">Nome do controle para o bind</param>
        /// <param name="fForm">formulário que o controle pertence</param>
        internal void setarValores_Bind(Control.ControlCollection controle, FormSet fForm)
        {
            if (string.IsNullOrEmpty(fForm.MainTabela))
            {
                MsgBox.Show("A propriedade MainTabela do form não foi preenchida."
                            , "Alerta"
                            , MessageBoxButtons.OK
                            , MessageBoxIcon.Error);
            }
            else
            {
                foreach (Control ctrl in controle)
                {
                    //-- Caso o controle possua mais controles internos.
                    if (ctrl.Controls.Count > 0 && ctrl.GetType() != typeof(cf_DateEdit))
                    {
                        //-- Caso seja um container de controles o metodo se chama automaticamente.
                        setarValores_Bind(ctrl.Controls, fForm);
                    }
                    else
                    {
                        if (ctrl.GetType().GetInterface("IBaseControl_DB", true) != null)
                        {
                            Interfaces.IBaseControl_DB cc = (Interfaces.IBaseControl_DB)ctrl;
                            if (!string.IsNullOrEmpty(cc.Tabela) && !string.IsNullOrEmpty(cc.ControlSource))
                            {
                                //-- Inicia o Bind
                                Binding b;

                                try
                                {
                                    //-- Captura todas as colunas da tabela que o controle está vinculado.
                                    DataColumn dcc = fForm.DataSetLocal.Tables[cc.Tabela].Columns[cc.ControlSource];

                                    switch (ctrl.GetType().Name)
                                    {
                                    case "cf_TextBox":
                                        b = new Binding("Text", fForm.BindingSource[cc.Tabela], cc.ControlSource);
                                        cf_TextBox control_text = (cf_Bases.cf_TextBox)ctrl;

                                        switch (control_text.TipoControles)
                                        {
                                        case CompSoft.TipoControle.Data:
                                            b.FormatString = "dd/MM/yyyy";
                                            break;

                                        case CompSoft.TipoControle.Hora:
                                            b.FormatString = "HH:mm";
                                            break;

                                        case CompSoft.TipoControle.Moeda:
                                            b.FormatString = "N2";
                                            break;

                                        case CompSoft.TipoControle.Numerico:
                                            b.FormatString = "N" + control_text.Qtde_Casas_Decimais.ToString();
                                            break;

                                        case CompSoft.TipoControle.Indice:
                                            b.FormatString = "F5";
                                            break;

                                        case CompSoft.TipoControle.Inteiro:
                                            b.FormatString = "D";
                                            break;

                                        default:
                                            b.FormatString = string.Empty;
                                            break;
                                        }
                                        b.FormattingEnabled    = true;
                                        b.DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;
                                        b.ControlUpdateMode    = ControlUpdateMode.OnPropertyChanged;

                                        if (control_text.MaxLength == 32767)
                                        {
                                            //-- Define o tamanho maximo do controle.
                                            control_text.MaxLength = this.Captura_MaxCaracter(dcc);
                                        }

                                        //-- Verifica a obrigatoriedade dos controles
                                        if (!cc.Obrigatorio)
                                        {
                                            if (fForm.MainTabela.ToLower().Equals(cc.Tabela.ToLower()))
                                            {
                                                cc.Obrigatorio = !dcc.AllowDBNull;
                                            }
                                        }
                                        break;

                                    case "cf_MaskedBox":
                                        b = new Binding("Text", fForm.BindingSource[cc.Tabela], cc.ControlSource);
                                        cf_MaskedBox control_mask = (cf_Bases.cf_MaskedBox)ctrl;

                                        b.FormattingEnabled    = false;
                                        b.DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;
                                        b.ControlUpdateMode    = ControlUpdateMode.OnPropertyChanged;

                                        if (control_mask.MaxLength == 32767)
                                        {
                                            //-- Define o tamanho maximo do controle.
                                            control_mask.MaxLength = this.Captura_MaxCaracter(dcc);
                                        }

                                        //-- Verifica a obrigatoriedade dos controles
                                        if (!cc.Obrigatorio)
                                        {
                                            if (fForm.MainTabela.ToLower().Equals(cc.Tabela.ToLower()))
                                            {
                                                cc.Obrigatorio = !dcc.AllowDBNull;
                                            }
                                        }
                                        break;

                                    case "cf_ComboBox":
                                        b = new Binding("SelectedValue", fForm.BindingSource[cc.Tabela], cc.ControlSource);
                                        b.FormattingEnabled    = false;
                                        b.DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;
                                        b.ControlUpdateMode    = ControlUpdateMode.OnPropertyChanged;

                                        ((CompSoft.cf_Bases.cf_ComboBox)ctrl).SelectedIndex = -1;

                                        //-- Verifica a obrigatoriedade dos controles
                                        if (!cc.Obrigatorio)
                                        {
                                            if (fForm.MainTabela.ToLower().Equals(cc.Tabela.ToLower()))
                                            {
                                                cc.Obrigatorio = !dcc.AllowDBNull;
                                            }
                                        }
                                        break;

                                    case "cf_CheckBox":
                                        b = new Binding("Checked", fForm.BindingSource[cc.Tabela], cc.ControlSource);
                                        b.FormattingEnabled    = true;
                                        b.DataSourceNullValue  = false;
                                        b.NullValue            = false;
                                        b.DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;
                                        b.ControlUpdateMode    = ControlUpdateMode.OnPropertyChanged;
                                        break;

                                    case "cf_RadioButton":
                                        b = new Binding("Checked", fForm.BindingSource[cc.Tabela], cc.ControlSource);
                                        b.FormattingEnabled    = true;
                                        b.DataSourceNullValue  = false;
                                        b.NullValue            = false;
                                        b.DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;
                                        b.ControlUpdateMode    = ControlUpdateMode.OnPropertyChanged;
                                        break;

                                    case "cf_DateEdit":
                                        b = new Binding("EditValue", fForm.BindingSource[cc.Tabela], cc.ControlSource);
                                        b.FormattingEnabled    = true;
                                        b.NullValue            = null;
                                        b.DataSourceNullValue  = DBNull.Value;
                                        b.DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;
                                        b.ControlUpdateMode    = ControlUpdateMode.OnPropertyChanged;

                                        //-- Verifica a obrigatoriedade dos controles
                                        if (!cc.Obrigatorio)
                                        {
                                            if (fForm.MainTabela.ToLower().Equals(cc.Tabela.ToLower()))
                                            {
                                                cc.Obrigatorio = !dcc.AllowDBNull;
                                            }
                                        }
                                        break;

                                    default:
                                        b = new Binding("Value", fForm.BindingSource[cc.Tabela], cc.ControlSource);
                                        b.FormattingEnabled    = true;
                                        b.DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;
                                        b.ControlUpdateMode    = ControlUpdateMode.OnPropertyChanged;
                                        b.FormatString         = string.Empty;
                                        break;
                                    }

                                    try
                                    {
                                        ctrl.DataBindings.Add(b);
                                    }
                                    catch
                                    {
                                        string sMsg = string.Empty;
                                        sMsg += "ERRO AO REALIZAR O BIND:";
                                        sMsg += "\n\r     -Controle: " + ctrl.Name;
                                        sMsg += "\n\r   -DataSource: " + b.DataSource.ToString();
                                        sMsg += "\n\r       -Tabela: " + cc.Tabela;
                                        sMsg += "\n\r       -Coluna: " + cc.ControlSource;
                                        MsgBox.Show(sMsg
                                                    , "Alerta"
                                                    , MessageBoxButtons.OK
                                                    , MessageBoxIcon.Error);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    string sMsg = string.Empty;
                                    sMsg += "ERRO AO REALIZAR O BIND:";
                                    sMsg += "\n\r     -Controle: " + ctrl.Name;
                                    sMsg += "\n\r       -Tabela: " + cc.Tabela;
                                    sMsg += "\n\r       -Coluna: " + cc.ControlSource;
                                    sMsg += "\n\r" + ex.Message;
                                    MsgBox.Show(sMsg
                                                , "Alerta"
                                                , MessageBoxButtons.OK
                                                , MessageBoxIcon.Error);
                                }
                            }
                        }
                    }
                }
            }
        }