/// <summary> /// Formata as colunas do grid de acordo com o objeto passado como parâmetro. /// </summary> /// <typeparam name="T">Um objeto do tipo TableAdapter.</typeparam> /// <param name="pGridView">O controle GridView.</param> /// <param name="dataBaseAdapter">Objeto do banco de dados</param> /// <param name="showDataSourceInformation">Exibi informações de Origem do Registros</param> /// <param name="pColumns">Uma lista de colunas.</param> public static void FormatGrid <T>( this GridView pGridView, DataBaseAdapter dataBaseAdapter, bool showDataSourceInformation = false, params KeyValuePair <string, Dictionary <object, string> >[] pColumns) where T : TableAdapter { var pObject = dataBaseAdapter.CreateObject <T>(); CreateColumn(pGridView, pObject.Collumns, pColumns); if (showDataSourceInformation) { pGridView.MouseMove += (sender, e) => { if (Keyboard.IsKeyDown(Keys.ControlKey)) { var hiBand = pGridView.CalcHitInfo(e.Location); if (hiBand.InColumnPanel) { if (!pObject.Collumns.Exists(c => c.Name == hiBand.Column.FieldName)) { return; } var tableAdapterField = pObject.Collumns[hiBand.Column.FieldName]; var informationSource = string.Format("[{0}]-[{1}]", tableAdapterField.TableAdapter.TableName, tableAdapterField.Name); Application.GetInstance().SetTextOnStatusBar(informationSource, BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Warning); } } }; } }
/// <summary> /// Preenche o grid de acordo com o objeto passado como parâmetro. /// </summary> /// <typeparam name="T">Um objeto do tipo TableAdapter.</typeparam> /// <param name="dataBaseAdapter">Objeto do banco de dados</param> /// <param name="pGridView">O controle GridView.</param> public static void FillAll <T>(this GridView pGridView, DataBaseAdapter dataBaseAdapter) where T : TableAdapter, new() { var table = dataBaseAdapter.CreateObject <T>(); pGridView.GridControl.DataSource = null; pGridView.GridControl.DataSource = table.FillCollection <T>(table.GetData().Rows); pGridView.BestFitColumns(); }
/// <summary> /// Formata as colunas do grid de acordo com o objeto passado como parâmetro. /// </summary> /// <typeparam name="T">Um objeto do tipo TableAdapter.</typeparam> /// <param name="pGridView">O controle GridView.</param> /// <param name="pDB">Objeto do banco de dados</param> /// <param name="pColumns">Uma lista de colunas.</param> public static void FormatGrid <T>( this DataGridTreeView pGridView, DataBaseAdapter pDB, params KeyValuePair <string, Dictionary <object, string> >[] pColumns) where T : TableAdapter { var pObject = pDB.CreateObject <T>(); TreeGridViewExtention.CreateColumn(pGridView, pObject.Collumns, pColumns); }
/// <summary> /// Formata as colunas do grid de acordo com o objeto passado como parâmetro. /// </summary> /// <typeparam name="T">Um objeto do tipo TableAdapter.</typeparam> /// <param name="pGridView">O controle GridView.</param> /// <param name="dataBaseAdapter">Adaptador de banco de dados</param> /// <param name="pColumns">Uma lista de colunas.</param> public static void FormatGrid <T>( this GridView pGridView, DataBaseAdapter dataBaseAdapter, params KeyValuePair <string, Dictionary <object, string> >[] pColumns) where T : TableAdapter { var pObject = dataBaseAdapter.CreateObject <T>(); CreateColumn(pGridView, pObject.Collumns, pColumns); }
CreateFormatGridParam <T>( DataBaseAdapter pDb, string pSourceColumnName, string pElementKey, params string[] pElementValue) where T : TableAdapter { var pObject = pDb.CreateObject <T>(); var values = pObject.GetData().ToDictionary(pElementKey, pElementValue); return(new KeyValuePair <string, Dictionary <object, string> >( pSourceColumnName, values)); }
/// <summary> /// Preenche o combobox com os valores de uma tabela ja instanciada e selecione o primeiro registro caso existir /// </summary> /// <typeparam name="t">Um TableAdapter</typeparam> /// <param name="pComboBox">Um combobox</param> /// <param name="pDB">Objeto do Banco de dado</param> /// <param name="pKey">Nome do Campo chave</param> /// <param name="pName">Descrição do Campo chave</param> /// <param name="pValue">Valor padrão</param> public static void FillValues <t> (this Nampula.UI.ComboBox pComboBox, DataBaseAdapter pDB, string pKey, string pName, object pValue) where t : TableAdapter, new() { var table = pDB.CreateObject <t>( ); var list = table.FillCollection <t>(table.GetData( ).Rows); pComboBox.ValidValues.Clear( ); foreach (var item in list) { pComboBox.ValidValues.Add( item.Collumns[pKey].Value, item.Collumns[pName].GetString( )); } if (pValue != null && !String.IsNullOrEmpty(pValue.ToString())) { pComboBox.Select(pValue, BoSearchKey.psk_ByValue); } else if (pComboBox.ValidValues.Count > 0) { pComboBox.Select(0, BoSearchKey.psk_Index); } }