コード例 #1
0
        public static void Teste(CParametreVisuDonneePrecalculee parametreVisu)
        {
            CResultAErreur result = parametreVisu.GetDataTable(CSc2iWin32DataClient.ContexteCourant);

            if (result)
            {
                CFormTestVisuTableauCroise form = new CFormTestVisuTableauCroise();
                form.m_parametre = parametreVisu;
                form.ShowDialog();
                form.Dispose();
            }
        }
コード例 #2
0
        void FillGrid(bool bAvecInterface)
        {
            CResultAErreur result = m_parametre.GetDataTable(m_contexteDonnee);

            if (!result)
            {
                if (bAvecInterface)
                {
                    CFormAlerte.Afficher(result.Erreur);
                }
                return;
            }
            try
            {
                DataTable table = result.Data as DataTable;
                m_grid.EnableHeadersVisualStyles = false;
                m_grid.ColumnHeadersVisible      = m_parametre.ShowHeader;
                m_table = table;
                DataView view = m_table.DefaultView;
                m_grid.AutoGenerateColumns = false;
                m_grid.DataSource          = view;

                m_grid.Columns.Clear();

                result = m_parametre.PrepareAffichageDonnees(table, m_contexteDonnee);
                m_grid.BackgroundColor = BackColor;

                m_grid.GridColor = ForeColor;

                DataGridViewCellStyle style = m_grid.ColumnHeadersDefaultCellStyle;
                CompleteFormatCellule(m_parametre.FormatHeader, style);
                style = m_grid.DefaultCellStyle;
                CompleteFormatCellule(m_parametre.FormatRows, style);

                /*style.SelectionBackColor = Color.FromArgb(255 - style.BackColor.R, 255 - style.BackColor.G, 255 - style.BackColor.B);
                 * style.SelectionForeColor = Color.FromArgb(255 - style.ForeColor.R, 255 - style.ForeColor.G, 255 - style.ForeColor.B);
                 */
                if (m_parametre.FormatRows.SelectionBackcolor.A == 0)
                {
                    style.SelectionForeColor = style.BackColor;
                    style.SelectionBackColor = style.ForeColor;
                }
                else
                {
                    style.SelectionForeColor = m_parametre.FormatRows.ForeColor;
                    style.SelectionBackColor = m_parametre.FormatRows.SelectionBackcolor;
                }


                List <CSortColumn> lstSort = new List <CSortColumn>();

                Dictionary <string, CParametreVisuChampTableauCroise> dicChampToParam = new Dictionary <string, CParametreVisuChampTableauCroise>();
                foreach (CParametreVisuChampTableauCroise pChamp in m_parametre.ParametresChamps)
                {
                    dicChampToParam[pChamp.ChampFinal.NomChamp] = pChamp;
                }

                string strColToMap = "";
                foreach (DataColumn col in new ArrayList(table.Columns))
                {
                    strColToMap = col.ColumnName;
                    CParametreVisuChampTableauCroise paramChamp = null;
                    CChampFinalDeTableauCroise       champFinal = col.ExtendedProperties[CTableauCroise.c_ExtendedPropertyToColumnKey] as CChampFinalDeTableauCroise;
                    DataGridViewColumn viewCol = null;
                    if (champFinal != null && dicChampToParam.TryGetValue(champFinal.NomChamp, out paramChamp))
                    {
                        if (paramChamp.ActionSurClick != null)
                        {
                            DataGridViewLinkColumn linkCol = new DataGridViewLinkColumn();
                            viewCol = linkCol;
                        }
                        DataColumn displayCol = col;
                        if (paramChamp.ChampFinal is CChampFinalDeTableauCroiseCle &&
                            paramChamp.FormuleData != null)
                        {
                            if (table.Columns.Contains(GetDisplayName(col.ColumnName)))
                            {
                                displayCol = table.Columns[GetDisplayName(col.ColumnName)];
                            }
                            else
                            {
                                //Crée une colonne _DISPLAY
                                displayCol = new DataColumn(GetDisplayName(col.ColumnName), typeof(string));
                                table.Columns.Add(displayCol);
                            }
                            strColToMap = displayCol.ColumnName;
                        }

                        if (paramChamp.SortOrder != null)
                        {
                            lstSort.Add(new CSortColumn(displayCol, paramChamp.SortOrder.Value, paramChamp.TriDecroissant));
                        }
                    }



                    if (viewCol == null)
                    {
                        viewCol = new DataGridViewTextBoxColumn();
                    }
                    m_grid.Columns.Add(viewCol);
                    viewCol.SortMode         = DataGridViewColumnSortMode.Programmatic;
                    viewCol.DataPropertyName = strColToMap;
                    viewCol.HeaderText       = col.ColumnName;
                }


                //m_grid.RowCount = Math.Max ( table.Rows.Count, 1 );
                CParametreDonneeCumulee parametreDonnee = null;
                CTypeDonneeCumulee      typeDonnee      = m_parametre.GetTypeDonneeCumulee(m_contexteDonnee);
                if (typeDonnee != null)
                {
                    parametreDonnee = typeDonnee.Parametre;
                }
                foreach (CParametreVisuChampTableauCroise paramChamp in m_parametre.ParametresChamps)
                {
                    foreach (DataGridViewColumn colView in m_grid.Columns)
                    {
                        DataColumn col = table.Columns[GetDataName(colView.DataPropertyName)];
                        if (col != null)
                        {
                            CChampFinalDeTableauCroise champFinal = col.ExtendedProperties[CTableauCroise.c_ExtendedPropertyToColumnKey] as CChampFinalDeTableauCroise;
                            if (champFinal != null && champFinal.NomChamp == paramChamp.ChampFinal.NomChamp)
                            {
                                m_dicColToParametreCol[colView.DataPropertyName] = paramChamp;
                                CompleteFormatCellule(paramChamp.FormatHeader, colView.HeaderCell.Style);
                                CompleteFormatCellule(paramChamp.FormatParDefaut, colView.DefaultCellStyle);

                                colView.HeaderCell.Value = paramChamp.GetValeurHeader(col, m_parametre);
                                if (paramChamp.FormatHeader.Width != null)
                                {
                                    colView.Width = paramChamp.FormatHeader.Width.Value;
                                }
                                if (paramChamp.FormuleData != null && champFinal is CChampFinalDeTableauCroiseCle)
                                {
                                    foreach (DataRow row in m_table.Rows)
                                    {
                                        row[GetDisplayName(col.ColumnName)] = paramChamp.GetValeurData(row[col], m_parametre);
                                    }
                                    colView.DataPropertyName = GetDisplayName(col.ColumnName);
                                }
                            }
                        }
                    }
                }

                lstSort.Sort(delegate(CSortColumn a, CSortColumn b)
                {
                    if (a.SortOrder == b.SortOrder)
                    {
                        return(a.Column.ColumnName.CompareTo(b.Column.ColumnName));
                    }
                    return(a.SortOrder.CompareTo(b.SortOrder));
                }
                             );
                string strSort = "";
                foreach (CSortColumn sortCol in lstSort)
                {
                    strSort += sortCol.Column.ColumnName;
                    if (sortCol.Decroissant)
                    {
                        strSort += " desc";
                    }
                    strSort += ",";
                }
                if (strSort.Length > 0)
                {
                    strSort   = strSort.Substring(0, strSort.Length - 1);
                    view.Sort = strSort;
                }

                AnalyseFiltres();
            }
            catch (Exception e)
            {
                result.EmpileErreur(new CErreurException(e));
                if (bAvecInterface)
                {
                    CFormAlerte.Afficher(result.Erreur);
                }
            }
        }