• 资源介绍
  • 更新记录
  • 评价建议
    • program.cs添加下面一行代码:

      static void Main() {
                  Application.EnableVisualStyles();
                  Application.SetCompatibleTextRenderingDefault(false);
      			DevExpress.Xpo.XpoDefault.DataLayer = new DevExpress.Xpo.SimpleDataLayer(new DevExpress.Xpo.DB.InMemoryDataStore());
                  Application.Run(new Form1());
              }

      custom class ,data object(自定义类):

      using System;
      using DevExpress.Xpo;
      
      namespace AdvancedSupportForEnums {
          public enum PersonGender { Mr, Mrs }
      
          public class Person : XPObject {
              public PersonGender Gender { get; set; }
              public DateTime DateOfBirth { get; set; }
              public Person Owner { get; set; }
              public string FirstName { get; set; }
              public Team Team { get; set; }
          }
      
          public class Team : XPObject {
              public string Name { get; set; }
          }
      }
      

      使用自定义类和xpcollection:

      using System;
      using System.IO;
      using System.Windows.Forms;
      using System.Collections.Generic;
      using DevExpress.Xpo;
      using DevExpress.XtraReports.UI;
      using DevExpress.XtraReports.Extensions;
      // ...
      
      namespace AdvancedSupportForEnums {
          public partial class Form1 : Form {
              static Form1() {
                  ReportDesignExtension.RegisterExtension(new CustomReportExtension(), TeamParameterName);
                  CustomReportStorageExtension.RegisterExtensionGlobal(new CustomReportStorageExtension());
              }
      
              private XtraReport report;
              private const string TeamParameterName = "Team";
      
              public Form1() {
                  InitializeComponent();
      
                  FillDataSource();
                  XPCollection<Person> dataSource = new XPCollection<Person>();
      
                  report = new XtraReport();
                  report.DataSource = dataSource;
      
                  ReportDesignExtension.AssociateReportWithExtension(report, TeamParameterName);
              }
      
              private void FillDataSource() {
                  if (new XPCollection<Person>().Count < 6) {
                      Team team1 = new Team() { Name = "Team 1" };
                      team1.Save();
                      Team team2 = new Team() { Name = "Team 2" };
                      team2.Save();
                      Team team3 = new Team() { Name = "Team 3" };
                      team3.Save();
      
                      new Person() {
                          FirstName = "Name 1, team1",
                          Team = team1,
                          DateOfBirth = DateTime.Now.AddYears(-1),
                          Gender = PersonGender.Mr
                      }.Save();
                      new Person() {
                          FirstName = "Name 1, team2",
                          Team = team2,
                          DateOfBirth = DateTime.Now,
                          Gender = PersonGender.Mrs
                      }.Save();
                      new Person() {
                          FirstName = "Name 1, team3",
                          Team = team3,
                          DateOfBirth = DateTime.Now,
                          Gender = PersonGender.Mrs
                      }.Save();
                      new Person() {
                          FirstName = "Name 2, team1",
                          Team = team1,
                          DateOfBirth = DateTime.Now.AddYears(-1),
                          Gender = PersonGender.Mr
                      }.Save();
                      new Person() {
                          FirstName = "Name 2, team2",
                          Team = team2,
                          DateOfBirth = DateTime.Now,
                          Gender = PersonGender.Mrs
                      }.Save();
                      new Person() {
                          FirstName = "Name 2, team3",
                          Team = team3,
                          DateOfBirth = DateTime.Now,
                          Gender = PersonGender.Mrs
                      }.Save();
                  }
              }
      
              private void btnDesigner_Click(object sender, EventArgs e) {
                  report.ShowDesignerDialog();
              }
      
              class CustomReportExtension : ReportDesignExtension {
                  public CustomReportExtension() {
                  }
      
                  public override void AddParameterTypes(IDictionary<Type, string> dictionary) {
                      dictionary.Add(typeof(PersonGender), "Person's Gender");
                  }
      
                  protected override bool CanSerialize(object data) {
                      return data is PersonGender;
                  }
                  protected override string SerializeData(object data, XtraReport report) {
                      return Enum.GetName(typeof(PersonGender), data);
                  }
                  protected override bool CanDeserialize(string value, string typeName) {
                      return typeof(PersonGender).FullName == typeName;
                  }
                  protected override object DeserializeData(string value, string typeName, XtraReport report) {
                      return Enum.Parse(typeof(PersonGender), value);
                  }
              }
      
              class CustomReportStorageExtension : ReportStorageExtension {
                  public override void SetData(XtraReport report, Stream stream) {
                      report.SaveLayoutToXml(stream);
                  }
                  public override void SetData(XtraReport report, string url) {
                      report.SaveLayoutToXml(url);
                  }
              }
          }
      }

      附录源代码demo


    Warning: Invalid argument supplied for foreach() in /data/wwwroot/www.lingkb.com/wp-content/plugins/riprodl/old.php on line 410

    发表评论

    售后服务:

    • 售后服务范围 1、问题免费咨询,只要站长会的一定回复
      2、源码收费安装、模板收费安装、服务答疑仅限SVIP用户
      3、单价超过200元的资源免费安装一次,需顾客提供服务器信息。
      付费增值服务 1、电脑软件定制开发,详情咨询QQ
      2、网站定制开发
      3、APP定制开发(Android & 苹果)
      4、系统搭建
      售后服务时间 周一至周日(法定节假日除外) 9:00-23:00
      免责声明 本站所提供的资源仅供学习交流,若使用商业用途,请购买正版授权,否则产生的一切后果将由下载用户自行承担,有部分资源为网上收集或仿制而来,若模板侵犯了您的合法权益,请来信通知我们(Email:[81160093@qq.com]),我们会及时删除,给您带来的不便,我们深表歉意!