コード例 #1
0
        private void FillMenuFiltre(int nColIndex, C2iWndDataGridColumn colonne)
        {
            m_nColIndexForFiltre = nColIndex;
            foreach (ToolStripItem item in new ArrayList(m_menuFiltreSpecial.DropDownItems))
            {
                m_menuFiltreSpecial.DropDownItems.Remove(item);
                if (item != m_valueSelector)
                {
                    item.Dispose();
                }
            }
            m_menuFiltreSpecial.DropDownItems.Clear();
            CGridFilterForWndDataGrid filtreActif = null;

            m_dicFiltre.TryGetValue(nColIndex, out filtreActif);
            IWndIncluableDansDataGrid wnd = colonne.Control as IWndIncluableDansDataGrid;

            if (wnd != null)
            {
                foreach (CGridFilterForWndDataGrid filtre in wnd.GetPossibleFilters())
                {
                    CGridFilterForWndDataGrid filtreToSet = filtre;
                    if (filtreActif != null && filtreActif.GetType() == filtre.GetType())
                    {
                        filtreToSet = filtreActif;
                    }
                    ToolStripMenuItem itemFiltre = new ToolStripMenuItem(filtreToSet.Label);
                    itemFiltre.Tag     = filtreToSet;
                    itemFiltre.Click  += new EventHandler(itemFiltre_Click);
                    itemFiltre.Checked = filtreToSet == filtreActif;
                    m_menuFiltreSpecial.DropDownItems.Add(itemFiltre);
                }
            }
            IEnumerable <object> source = m_listeObjetsOriginale;

            if (source != null)
            {
                CGridFilterListeValeurs             filtreListe = filtreActif as CGridFilterListeValeurs;
                List <CCoupleValeurEtValeurDisplay> lstValeurs  = new List <CCoupleValeurEtValeurDisplay>();
                if (filtreListe == null)
                {
                    source = m_grid.DataSource as IEnumerable <object>;
                }
                foreach (object obj in source)
                {
                    CCoupleValeurEtValeurDisplay valeur = m_cache.GetValeur(obj, nColIndex, false);
                    if (valeur != null)
                    {
                        lstValeurs.Add(valeur);
                    }
                }
                m_valueSelector.Selector.FillWithValues(lstValeurs.ToArray(), filtreListe);
                if (!m_menuFiltre.Items.Contains(m_valueSelector))
                {
                    m_menuFiltre.Items.Add(m_valueSelector);
                }
            }
        }
コード例 #2
0
        public C2iWndDataGridColumn AddColumn(
            string strLibelle,
            IWndIncluableDansDataGrid wnd)
        {
            C2iWndDataGridColumn col = new C2iWndDataGridColumn();

            col.Text        = strLibelle;
            col.ColumnWidth = ((C2iWnd)wnd).Size.Width;
            col.Control     = (C2iWnd)wnd;
            m_wndGrid.AddChild(col);
            col.Parent = m_wndGrid;
            return(col);
        }
コード例 #3
0
 public CDataGridViewCustomCellFor2iWnd(
     CGridDataCache datas,
     C2iWndDataGridColumn wndCol,
     int nColumnIndex,
     IWndIncluableDansDataGrid wndAssociee,
     IFournisseurProprietesDynamiques fournisseur)
     : base()
 {
     m_datas        = datas;
     m_nColumnIndex = nColumnIndex;
     m_2iWndForGrid = wndAssociee;
     m_fournisseur  = fournisseur;
     m_wndCol       = wndCol;
 }
コード例 #4
0
ファイル: CGridDataCache.cs プロジェクト: ykebaili/sc2idlls
        public object GetElementEdite(object source, int nColumnIndex)
        {
            if (source == null)
            {
                return(null);
            }
            Dictionary <object, object> dicObjetToElementEdite = null;
            C2iExpression formule = null;

            if (!m_dicNumColToFormuleElementEdite.TryGetValue(nColumnIndex, out formule))
            {
                C2iWndDataGridColumn col = m_grid.WndGrid.GetColumn(nColumnIndex);
                if (col != null)
                {
                    formule = col.AlternativeEditedElement;
                }
                m_dicNumColToFormuleElementEdite[nColumnIndex] = formule;
            }
            if (!m_dicColToObjetsEdites.TryGetValue(nColumnIndex, out dicObjetToElementEdite))
            {
                if (formule != null)
                {
                    dicObjetToElementEdite = new Dictionary <object, object>();
                    m_dicColToObjetsEdites[nColumnIndex] = dicObjetToElementEdite;
                }
            }
            object retour = source;

            if (dicObjetToElementEdite != null)
            {
                retour = null;
                if (!dicObjetToElementEdite.TryGetValue(source, out retour))
                {
                    CContexteEvaluationExpression ctx = new CContexteEvaluationExpression(source);
                    try
                    {
                        CResultAErreur result = formule.Eval(ctx);
                        if (result)
                        {
                            retour = result.Data;
                        }
                    }
                    catch { }
                    dicObjetToElementEdite[source] = retour;
                }
            }
            return(retour);
        }
コード例 #5
0
        public static void Show(
            C2iWndDataGridColumn col,
            int nColumnIndex,
            string strText,
            int nWidth,
            OnFiltrerDataGridEventHandler handler)
        {
            CFormFiltreDataGrid form = new CFormFiltreDataGrid();

            form.m_txtFiltre.Text      = strText;
            form.m_lblNomCol.BackColor = col.BackColor;
            form.m_lblNomCol.Text      = col.Text;
            form.m_handler             = handler;
            form.m_nColumnIndex        = nColumnIndex;
            form.Show();
        }
コード例 #6
0
 private void m_grid_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
 {
     if (e.RowIndex == -1 && e.ColumnIndex >= 0)
     {
         Rectangle rct = e.CellBounds;
         rct.Inflate(-1, -1);
         CGridFilterForWndDataGrid filtre = null;
         m_dicFiltre.TryGetValue(e.ColumnIndex, out filtre);
         C2iWndDataGridColumn col = m_wndGrid.GetColumn(e.ColumnIndex);
         bool bHasFiltre          = col != null && col.AllowFilter;
         if (bHasFiltre)
         {
             rct = new Rectangle(rct.Location, new Size(rct.Size.Width - c_nWidthImageHeader, rct.Height));
         }
         DataGridViewCellStyle style = m_grid.Columns[e.ColumnIndex].HeaderCell.Style;
         Brush br = new SolidBrush(style.BackColor);
         e.Graphics.FillRectangle(br, e.CellBounds);
         br.Dispose();
         Pen pen = new Pen(m_grid.GridColor);
         e.Graphics.DrawRectangle(pen, new Rectangle(e.CellBounds.Location, new Size(e.CellBounds.Width - 1, e.CellBounds.Height - 1)));
         br = new SolidBrush(style.ForeColor);
         e.Graphics.DrawString(m_grid.Columns[e.ColumnIndex].HeaderText, style.Font, br, rct);
         br.Dispose();
         if (bHasFiltre)
         {
             if (filtre != null)
             {
                 e.Graphics.DrawImageUnscaled(Properties.Resources.filtre, new Point(rct.Right, rct.Top));
             }
             else
             {
                 e.Graphics.DrawImageUnscaled(Properties.Resources.FiltreListe, new Point(rct.Right, rct.Top));
             }
         }
         e.Handled = true;
     }
 }
コード例 #7
0
        private void m_grid_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
            {
                C2iWndDataGridColumn col = m_wndGrid.GetColumn(e.ColumnIndex);
                Rectangle            rct = m_grid.GetColumnDisplayRectangle(e.ColumnIndex, false);
                if (e.X > rct.Width - c_nWidthImageHeader)//Filtre
                {
                    if (col != null && col.AllowFilter)
                    {
                        FillMenuFiltre(e.ColumnIndex, col);
                        DataGridViewColumn gvCol = m_grid.Columns[e.ColumnIndex];
                        rct        = m_grid.GetColumnDisplayRectangle(e.ColumnIndex, true);
                        rct.Height = gvCol.HeaderCell.ContentBounds.Height;

                        m_menuFiltre.Show(m_grid, rct.Left, rct.Bottom);

                        /*}
                         * else
                         * {
                         *  string strText = null;
                         *  if (!m_dicFiltre.TryGetValue(e.ColumnIndex, out strText))
                         *      strText = "";
                         *  CFormFiltreDataGrid.OnFiltrerDataGridEventHandler handler = new CFormFiltreDataGrid.OnFiltrerDataGridEventHandler(OnFiltrer);
                         *  CFormFiltreDataGrid.Show(col, e.ColumnIndex, strText, rct.Width, handler);
                         * }*/
                    }
                }
                else
                {
                    if (col != null && col.AllowSort)
                    {
                        Sort(e.ColumnIndex);
                    }
                }
            }
        }
コード例 #8
0
        public void Init(
            CWndFor2iDataGrid wndFor2iDataGrid,
            C2iWndDataGrid wndGrid,
            object elementEdite,
            List <object> lstObjets,
            IFournisseurProprietesDynamiques fournisseur)
        {
            m_wndFor2iDataGrid     = wndFor2iDataGrid;
            m_listeObjetsOriginale = lstObjets;
            m_fournisseur          = fournisseur;
            m_wndGrid      = wndGrid;
            m_elementEdite = elementEdite;
            if (m_cache != null)
            {
                m_cache.Dispose();
            }
            m_cache = new CGridDataCache(this);


            List <object> listeObjets = new List <object>(lstObjets);

            foreach (object newElt in m_listeElementsAdd)
            {
                if (!lstObjets.Contains(newElt))
                {
                    lstObjets.Add(newElt);
                }
            }

            m_panelTop.Visible  = m_wndGrid.HasAddButton || m_wndGrid.HasDeleteButton;
            m_lnkAdd.Visible    = m_wndGrid.HasAddButton;
            m_lnkDelete.Visible = m_wndGrid.HasDeleteButton;

            m_grid.AutoGenerateColumns = false;
            Filtrer();
            m_grid.SuspendDrawing();
            //m_grid.DataSource = lstObjets;
            m_grid.Columns.Clear();
            int nMaxHeight = m_grid.ColumnHeadersHeight;

            m_grid.EnableHeadersVisualStyles            = false;
            m_grid.RowHeadersVisible                    = m_wndGrid.RowHeaderWidth != 0;
            m_grid.RowHeadersWidth                      = Math.Max(m_wndGrid.RowHeaderWidth, 10);
            m_grid.RowHeadersDefaultCellStyle.BackColor = m_wndGrid.RowHeaderColor;
            m_grid.BackgroundColor                      = m_wndGrid.BackColor;
            m_grid.DefaultCellStyle.SelectionBackColor  = m_wndGrid.SelectedCellBackColor;
            m_grid.DefaultCellStyle.SelectionForeColor  = m_wndGrid.SelectedCellForeColor;
            m_grid.EditMode = DataGridViewEditMode.EditOnEnter;
            if (m_wndGrid.DefaultRowHeight > 0)
            {
                m_grid.RowTemplate.Height = m_wndGrid.DefaultRowHeight;
            }
            int nCol = 0;

            foreach (I2iObjetGraphique obj in m_wndGrid.Childs)
            {
                C2iWndDataGridColumn          col     = obj as C2iWndDataGridColumn;
                CContexteEvaluationExpression ctxEval = new CContexteEvaluationExpression(m_elementEdite);
                //Evalue la formule de visibilité
                if (col.Visiblity != null)
                {
                    CResultAErreur res = col.Visiblity.Eval(ctxEval);
                    if (res && !CUtilBool.BoolFromObject(res.Data))
                    {
                        col = null;
                    }
                }
                if (col != null)
                {
                    IWndIncluableDansDataGrid wndForGrid = col.Control as IWndIncluableDansDataGrid;
                    m_cache.RegisterControle(nCol, wndForGrid);
                    nCol++;
                    if (wndForGrid != null)
                    {
                        DataGridViewColumn gridCol = new DataGridViewColumn(
                            new CDataGridViewCustomCellFor2iWnd(m_cache, col, nCol - 1, wndForGrid, m_fournisseur)
                            );
                        if (col.Enabled != null)
                        {
                            CResultAErreur result = col.Enabled.Eval(ctxEval);
                            if (result && !CUtilBool.BoolFromObject(result.Data))
                            {
                                gridCol.ReadOnly = true;
                            }
                        }
                        gridCol.HeaderText = col.Text;
                        gridCol.Width      = col.ColumnWidth;
                        DataGridViewCellStyle style = new DataGridViewCellStyle();
                        style.BackColor          = col.BackColor;
                        style.ForeColor          = col.ForeColor;
                        style.Font               = col.Font;
                        gridCol.HeaderCell.Style = style;

                        if (col.Control != null)
                        {
                            DataGridViewCellStyle styleCell = new DataGridViewCellStyle();
                            styleCell.Font             = col.Control.Font;
                            styleCell.BackColor        = col.Control.BackColor;
                            styleCell.ForeColor        = col.Control.ForeColor;
                            styleCell.WrapMode         = DataGridViewTriState.True;
                            gridCol.CellTemplate.Style = styleCell;
                        }
                        m_grid.Columns.Add(gridCol);
                        nMaxHeight = Math.Max(col.Size.Height, nMaxHeight);
                    }
                }
            }
            m_grid.ResumeDrawing();
            m_grid.ColumnHeadersHeight = nMaxHeight;
            InitRestrictions(m_listeRestrictions);
        }
コード例 #9
0
        private void Filtrer()
        {
            List <object> lst = m_listeObjetsOriginale;

            if (lst == null)
            {
                return;
            }
            using (CWaitCursor waiter = new CWaitCursor())
            {
                bool bCancel = false;
                foreach (KeyValuePair <int, CGridFilterForWndDataGrid> kv in m_dicFiltre)
                {
                    if (kv.Value != null)
                    {
                        CGridFilterForWndDataGrid filter = kv.Value;
                        C2iWndDataGridColumn      col    = m_wndGrid.GetColumn(kv.Key);
                        IWndIncluableDansDataGrid ctrl   = col.Control as IWndIncluableDansDataGrid;
                        if (ctrl != null)
                        {
                            List <object> lst2 = new List <object>();
                            foreach (object obj in lst)
                            {
                                int nVal = (int)Keys.Escape;

                                nVal = GetKeyState((int)Keys.Escape);
                                if (nVal < 0)
                                {
                                    bCancel = true;
                                    break;
                                }
                                CCoupleValeurEtValeurDisplay dataVal = m_cache.GetValeur(obj, kv.Key, col.MultiThread);
                                if (dataVal != null && filter.IsValueIn(dataVal.ObjectValue))
                                {
                                    lst2.Add(obj);
                                }
                            }
                            lst = lst2;
                        }
                    }
                    if (bCancel)
                    {
                        break;
                    }
                }
                if (bCancel)
                {
                    lst = m_listeObjetsOriginale;
                    MessageBox.Show(I.T("Filter has been canceled|20019"));
                }
            }
            if (m_nColumnSort != null)
            {
                try
                {
                    lst.Sort(new CGridSorter(m_nColumnSort.Value, m_bSortAsc, m_cache));
                }
                catch { }
            }
            m_grid.DataSource = lst;
            foreach (DataGridViewColumn col in m_grid.Columns)
            {
                CDataGridViewCustomCellFor2iWnd cell = col.CellTemplate as CDataGridViewCustomCellFor2iWnd;
            }
        }