.NET 學習

.NET 學習生活感想... 万事成蹉跎..... 贵在坚持 及时整理自己做过和学过的东西

博客园 首页 新随笔 联系 订阅 管理
using System;
using System.Collections.Generic;

using DevExpress.ExpressApp;
using DevExpress.XtraPivotGrid;
using DevExpress.ExpressApp.PivotGrid.Win;
using DevExpress.ExpressApp.Model;

namespace DXExample.Module
{
    
public class Q326025Controller : ViewController<ListView>
    {
        
private const string PivotGridListEditorKey = "PivotGridListEditor";

        
private void Q326025Controller_FieldValueDisplayText(object sender, PivotFieldDisplayTextEventArgs e)
        {
            
string displayText = GetDisplayText(e.Field, e.Value);
            
if (!string.IsNullOrEmpty(displayText))
            {
                e.DisplayText 
= displayText;
            }
        }
        
private void Q326025Controller_CustomCellDisplayText(object sender, PivotCellDisplayTextEventArgs e)
        {
            
string displayText = GetDisplayText(e.DataField, e.Value);
            
if (!string.IsNullOrEmpty(displayText))
            {
                e.DisplayText 
= displayText;
            }
            
if(e.Value != null)
            {
                
switch (int.Parse(e.Value.ToString()))
                {
                    
case -1:
                        e.DisplayText 
= "正常班";
                        
break;
                    
case -2:
                        e.DisplayText 
= "事假";
                        
break;
                }
            }
        }

        
private PivotGridListEditor PivotGridListEditor
        {
            
get { return View.Editor as PivotGridListEditor; }
        }

        
protected virtual string GetDisplayText(PivotGridFieldBase field, object value)
        {
            
if (field != null && value != null && value.GetType() == typeof(bool))
            {
                IModelMember modelMember 
= View.Model.ModelClass.FindMember(field.FieldName);
                
if (modelMember != null)
                {
                    
if ((bool)value)
                    {
                        
if (!string.IsNullOrEmpty(modelMember.CaptionForTrue))
                        {
                            
return modelMember.CaptionForTrue;
                        }
                    }
                    
else
                    {
                        
if (!string.IsNullOrEmpty(modelMember.CaptionForFalse))
                        {
                            
return modelMember.CaptionForFalse;
                        }
                    }
                }
            }
            
return null;
        }
        
protected override void OnViewChanging(View view)
        {
            
base.OnViewChanging(view);
            Active.RemoveItem(PivotGridListEditorKey);
            
if (view is ListView)
            {
                Active[PivotGridListEditorKey] 
= ((ListView)view).Editor is PivotGridListEditor;
            }
        }
        
protected override void OnViewControlsCreated()
        {
            
base.OnViewControlsCreated();
            ((PivotGridControl)(PivotGridListEditor.PivotGridControl)).CustomCellDisplayText 
+= new
    PivotCellDisplayTextEventHandler(Q326025Controller_CustomCellDisplayText);
            ((PivotGridControl)(PivotGridListEditor.PivotGridControl)).FieldValueDisplayText 
+= new
    PivotFieldDisplayTextEventHandler(Q326025Controller_FieldValueDisplayText);
        }
        
protected override void OnDeactivated()
        {
            ((PivotGridControl)(PivotGridListEditor.PivotGridControl)).CustomCellDisplayText 
-= new
    PivotCellDisplayTextEventHandler(Q326025Controller_CustomCellDisplayText);
            ((PivotGridControl)(PivotGridListEditor.PivotGridControl)).FieldValueDisplayText 
-= new
    PivotFieldDisplayTextEventHandler(Q326025Controller_FieldValueDisplayText);
            
base.OnDeactivated();
        }
    }

} 

 

 

 

posted on 2011-07-24 09:53  Tonyyang  阅读(912)  评论(0编辑  收藏  举报
欢迎转载,转载请注明出处:http://www.cnblogs.com/Tonyyang/