基于XPO创建ZeroCode数据感知Winform应用程序

Visual Studio V2019

Net.Framework V4.6.1

创建一个WinForm应用程序

Step 1:修改Program.cs

 

using DevExpress.Xpo;
using DevExpress.Xpo.DB;

    static class Program
    {
        //public const string ConnectionString = @"XpoProvider=MSSqlServer;data source=(local);integrated security=SSPI;initial catalog=XpoTutorial1";
        public const string ConnectionString = @"XpoProvider=MSAccess;Provider=Microsoft.Jet.OLEDB.4.0;Mode=Share Deny None;data source=E:\DEV_TEST\Report_Test\Report_Test\test.MDB;user id=;password=;";

        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            XpoDefault.DataLayer = XpoDefault.GetDataLayer(ConnectionString, AutoCreateOption.DatabaseAndSchema);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new XtraForm1());
        }
}

Step 2:创建Code First:

public class Customer : XPObject

{

    public Customer() : base()

    {

        // This constructor is used when an object is loaded from a persistent storage.

        // Do not place any code here.

    }



    public Customer(Session session) : base(session)

    {

        // This constructor is used when an object is loaded from a persistent storage.

        // Do not place any code here.

    }



    string fName;

    public string Name

    {

        get { return fName; }

        set { SetPropertyValue<string>("Name", ref fName, value); }

    }

    ushort fAge;

    public ushort Age

    {

        get { return fAge; }

        set { SetPropertyValue<ushort>("Age", ref fAge, value); }

    }



    public override void AfterConstruction()

    {

        base.AfterConstruction();

        // Place here your initialization code.

    }

}

Step 3:添加XtraForm1

拖控件:

拖GridControl

设置XPCollection属性

设置GridControl属性:

代码:

public partial class XtraForm1 : DevExpress.XtraEditors.XtraForm

{

    public XtraForm1()

    {

        InitializeComponent();

    }



    private void XtraForm1_Load(object sender, EventArgs e)

    {

        if (xpCollection1.Count == 0)

        {

            var customer1 = new Customer(session1);

            customer1.Name = "John";

            customer1.Age = 21;

            customer1.Save();

            xpCollection1.Add(customer1);

            var customer2 = new Customer(session1);

            customer2.Name = "Bob";

            customer2.Age = 37;

            customer2.Save();

            xpCollection1.Add(customer2);

        }

    }

效果:

使用代码设置属性:

XPCollection xpCollectionPerson = new XPCollection(typeof(Person));

xpCollectionPerson.DisplayableProperties = "Name;Group.GroupName";

gridControl1.DataSource = xpCollectionPerson;



gridControl1.UseEmbeddedNavigator = true;



// Create an XPClassInfo object corresponding to the Person_Contact class.

XPClassInfo classInfo = XpoDefault.Session.GetClassInfo(typeof(Person_Contact));

// Create a filter that selects records which contain names starting with 'A'

// in the LastName column

CriteriaOperator criteria = CriteriaOperator.Parse("[LastName] LIKE ?", "A%");

//Create a data source.

XPServerCollectionSource serverModeDS = new XPServerCollectionSource(

XpoDefault.Session, classInfo, criteria);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qq_16215957

如果有帮助一杯咖啡奶茶均可

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值