첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

▶ TestObject.cs

using System;

using DevExpress.Xpo;

namespace HowToImplementTheInstantFeedbackModeXPO
{
    /// <summary>
    /// 테스트 객체
    /// </summary>
    public class TestObject : XPObject
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 주제
        /// </summary>
        private string subject;

        /// <summary>
        /// 송신 일시
        /// </summary>
        private DateTime sendTime;

        /// <summary>
        /// 첨부 여부
        /// </summary>
        private bool hasAttachment;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 주제 - Subject

        /// <summary>
        /// 주제
        /// </summary>
        public string Subject
        {
            get
            { 
                return this.subject;
            }
            set
            { 
                SetPropertyValue<string>("Subject", ref this.subject, value);
            }
        }

        #endregion

        #region 송신 일시 - SendTime

        /// <summary>
        /// 송신 일시
        /// </summary>
        public DateTime SendTime
        {
            get
            {
                return this.sendTime;
            }
            set
            {
                SetPropertyValue<DateTime>("SendTime", ref this.sendTime, value);
            }
        }

        #endregion

        #region 첨부 여부 - HasAttachment

        /// <summary>
        /// 첨부 여부
        /// </summary>
        public bool HasAttachment
        {
            get
            { 
                return this.hasAttachment;
            }
            set
            { 
                SetPropertyValue<bool>("HasAttachment", ref this.hasAttachment, value);
            }
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - TestObject()

        /// <summary>
        /// 생성자
        /// </summary>
        public TestObject() : base(Session.DefaultSession)
        {
        }

        #endregion

        #region 생성자 - TestObject(session)

        /// <summary>
        /// 생성자
        /// </summary>
        /// <param name="session">Session 객체</param>
        public TestObject(Session session) : base(session)
        {
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성 후 처리하기 - AfterConstruction()

        /// <summary>
        /// 생성 후 처리하기
        /// </summary>
        public override void AfterConstruction()
        {
            base.AfterConstruction();
        }

        #endregion
    }
}

 

728x90

 

▶ MainPage.xaml

<Window
    x:Class="HowToImplementTheInstantFeedbackModeXPO.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
    Width="800"
    Height="600"
    Title="Implement The Instant Feedback Mode (XPO)">
    <Grid>
        <dxg:GridControl x:Name="gridControl"
            AutoGenerateColumns="AddNew" />
    </Grid>
</Window>

 

300x250

 

▶ MainPage.xaml.cs

using System;
using System.Windows;

using DevExpress.Xpo;

namespace HowToImplementTheInstantFeedbackModeXPO
{
    /// <summary>
    /// 메인 윈도우
    /// </summary>
    public partial class MainWindow : Window
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainWindow()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainWindow()
        {
            InitializeDataAccessLayer();

            GenerateTestData(100000);

            InitializeComponent();
            
            XPInstantFeedbackSource xpInstantFeedbackSource = new XPInstantFeedbackSource(typeof(TestObject));

            xpInstantFeedbackSource.ResolveSession += xpInstantFeedbackSource_ResolveSession;
            xpInstantFeedbackSource.DismissSession += xpInstantFeedbackSource_DismissSession;
            
            this.gridControl.ItemsSource = xpInstantFeedbackSource;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private
        //////////////////////////////////////////////////////////////////////////////// Event

        #region XP 즉시 피드백 소스 세션 Resolve 처리하기 - xpInstantFeedbackSource_ResolveSession(sender, e)

        /// <summary>
        /// XP 즉시 피드백 소스 세션 Resolve 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void xpInstantFeedbackSource_ResolveSession(object sender, ResolveSessionEventArgs e)
        {
            e.Session = new UnitOfWork();
        }

        #endregion

        #region XP 즉시 피드백 소스 세션 Dismiss 처리하기 - xpInstantFeedbackSource_DismissSession(sender, e)

        /// <summary>
        /// XP 즉시 피드백 소스 세션 Dismiss 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void pXPInstantFeedbackSource_DismissSession(object sender, ResolveSessionEventArgs e)
        {
            IDisposable disposable = e.Session as IDisposable;

            if(disposable != null)
            {
                disposable.Dispose();
            }
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////// Function

        #region 데이터 액세스 레이어 초기화 하기 - InitializeDataAccessLayer()

        /// <summary>
        /// 데이터 액세스 레이어 초기화 하기
        /// </summary>
        private static void InitializeDataAccessLayer()
        {
            XpoDefault.Session = null;

            XpoDefault.DataLayer = XpoDefault.GetDataLayer
            (
                DevExpress.Xpo.DB.AccessConnectionProvider.GetConnectionString("test.mdb"),
                DevExpress.Xpo.DB.AutoCreateOption.DatabaseAndSchema
            );
        }

        #endregion

        #region 테스트 데이터 생성하기 - GenerateTestData(recordCount)

        /// <summary>
        /// 테스트 데이터 생성하기
        /// </summary>
        /// <param name="recordCount">레코드 수</param>
        private void GenerateTestData(int recordCount)
        {
            using(UnitOfWork unitOfWork = new UnitOfWork())
            {
                if(unitOfWork.FindObject<TestObject>(null) != null)
                {
                    return;
                }

                for(int i = 0; i < recordCount; i++)
                {
                    TestObject testObject = new TestObject(unitOfWork)
                    {
                        HasAttachment = false,
                        Sent          = DateTime.Now,
                        Subject       = string.Format("Subject {0}", i)
                    };
                }

                unitOfWork.CommitChanges();
            }
        }

        #endregion
    }
}

 

728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요