Пример #1
0
        public void Init(
            CParametreVisuChampTableauCroise parametre,
            CParametreVisuDonneePrecalculee parametreVisuDonneePrecalculee,
            CContexteDonnee contexteDonnee)
        {
            if (m_parametreVisuChamp != null)
            {
                MajChamps();
            }
            m_contexteDonnee      = contexteDonnee;
            m_parametreVisuDonnee = parametreVisuDonneePrecalculee;
            m_parametreVisuChamp  = parametre;
            if (parametre == null)
            {
                Visible = false;
                return;
            }
            Visible = true;
            CTypeDonneeCumulee      typeDonnee      = m_parametreVisuDonnee.GetTypeDonneeCumulee(m_contexteDonnee);
            CParametreDonneeCumulee parametreDonnee = null;

            if (typeDonnee != null)
            {
                parametreDonnee = typeDonnee.Parametre;
            }

            m_lblNomChamp.Text = parametre.ChampFinal.NomChamp;
            m_panelFormatStandard.Init(m_parametreVisuChamp.FormatParDefaut,
                                       parametre.GetObjetPourFormuleData(parametreDonnee), false);
            m_panelFormatHeader.Init(m_parametreVisuChamp.FormatHeader, null, true);


            CElementAVariablesDynamiques obj = m_parametreVisuChamp.GetObjetPourFormuleHeader(parametreDonnee);

            m_txtFormuleHeader.Init(obj,
                                    new CObjetPourSousProprietes(obj));

            obj = m_parametreVisuChamp.GetObjetPourFormuleData(parametreDonnee);
            m_txtFormuleData.Init(obj,
                                  new CObjetPourSousProprietes(obj));

            m_txtFormuleData.Formule   = m_parametreVisuChamp.FormuleData;
            m_txtFormuleHeader.Formule = m_parametreVisuChamp.FormuleHeader;
            m_txtSortOrder.IntValue    = m_parametreVisuChamp.SortOrder;
            m_chkDecroissant.Checked   = m_parametreVisuChamp.TriDecroissant;

            m_imageLink.Visible = m_parametreVisuChamp.ActionSurClick != null;
        }
Пример #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);
                }
            }
        }