コード例 #1
0
        public static void SetXpMemberProperty(string propertyName, object value, XPBaseObject dbObject, bool save)
        {
            if (propertyName.IndexOf(".") > -1)
            {
                XPMemberInfo member = dbObject.ClassInfo.GetMember(propertyName.Split(".".ToCharArray())[0]);
                object       o      = member.GetValue(dbObject);
                if (typeof(XPBaseObject).IsAssignableFrom(member.MemberType))
                {
                    dbObject = o as XPBaseObject;
                    SetXpMemberProperty(propertyName.Substring(propertyName.IndexOf(".") + 1), value, dbObject, save);
                    return;
                }
                SetPropertyValue(o.GetType().GetProperty(propertyName.Substring(propertyName.IndexOf(".") + 1)), o,
                                 value);
                return;
            }
            XPMemberInfo xpMemberInfo = dbObject.ClassInfo.GetMember(propertyName);

            if (xpMemberInfo == null)
            {
                throw new PropertyMissingException(dbObject.GetType().FullName, propertyName);
            }
            xpMemberInfo.SetValue(dbObject,
                                  xpMemberInfo.Owner.ClassType.GetProperty(propertyName) == null
                                      ? value
                                      : ChangeType(value, xpMemberInfo.MemberType));
            if (save)
            {
                dbObject.Save();
            }
        }
 private void OnAppointmentCollectionChanged(object sender, PersistentObjectsEventArgs e)
 {
     foreach (Appointment apt in e.Objects)
     {
         XPBaseObject o = apt.GetSourceObject(schedulerStorage) as XPBaseObject;
         if (o != null)
         {
             o.Save();
         }
     }
 }
 void OnAppointmentsChanged(object sender, PersistentObjectsEventArgs e)
 {
     foreach (Appointment apt in e.Objects)
     {
         XPBaseObject o = apt.GetSourceObject((SchedulerDataStorage)sender) as XPBaseObject;
         if (o != null)
         {
             o.Save();
         }
     }
 }
コード例 #4
0
 private void schedulerStorage1_AppointmentsInserted(object sender, PersistentObjectsEventArgs e)
 {
     foreach (Appointment apt in e.Objects)
     {
         XPBaseObject o = apt.GetSourceObject(schedulerStorage1) as XPBaseObject;
         if (o != null)
         {
             o.Save();
         }
     }
 }
コード例 #5
0
 private void schedulerStorage1_AppointmentsChanged(object sender, DevExpress.XtraScheduler.PersistentObjectsEventArgs e)
 {
     foreach (Appointment apt in e.Objects)
     {
         XPBaseObject o = apt.GetSourceObject(schedulerStorage1) as XPBaseObject;
         if (o != null)
         {
             o.Save();
         }
     }
 }
 private void SchedulerStorage_AppointmentsModified(object sender, PersistentObjectsEventArgs e)
 {
     foreach (Appointment apt in e.Objects)
     {
         XPBaseObject o = apt.GetSourceObject(schedulerControl1.Storage.GetCoreStorage()) as XPBaseObject;
         if (o != null)
         {
             o.Save();
         }
     }
 }
 private void schedulerStorage1_AppointmentDependenciesChanged(object sender, PersistentObjectsEventArgs e)
 {
     foreach (AppointmentDependency dependency in e.Objects)
     {
         XPBaseObject xpObject = dependency.GetSourceObject(schedulerStorage1) as XPBaseObject;
         if (xpObject != null)
         {
             xpObject.Save();
         }
     }
 }
コード例 #8
0
        static void Main(string[] args)
        {
            IDataStore provider = new DevExpress.Xpo.DB.InMemoryDataStore();
            //string connectionString = MSSqlConnectionProvider.GetConnectionString("localhost", "E1139");
            //IDataStore provider = XpoDefault.GetConnectionProvider(connectionString, AutoCreateOption.DatabaseAndSchema);

            XPDictionary dictionary  = new ReflectionDictionary();
            XPClassInfo  myBaseClass = dictionary.GetClassInfo(typeof(MyBaseObject));
            XPClassInfo  myClassA    = dictionary.CreateClass(myBaseClass, "MyObjectA");

            myClassA.CreateMember("ID", typeof(int), new KeyAttribute(true));
            myClassA.CreateMember("Name", typeof(string));

            XpoDefault.Session   = null;
            XpoDefault.DataLayer = new SimpleDataLayer(dictionary, provider);
            //XpoDefault.DataLayer = new ThreadSafeDataLayer(dictionary, provider);

            using (Session session = new Session()) {
                session.UpdateSchema(myClassA);
            }
            using (Session session = new Session()) {
                Console.WriteLine("Create a new object:");
                XPBaseObject obj = (XPBaseObject)myClassA.CreateNewObject(session);
                obj.SetMemberValue("Name", String.Format("sample {0}", DateTime.UtcNow.Ticks));
                obj.Save();
                Console.WriteLine("ID:\t{0}, Name:\t{1}", obj.GetMemberValue("ID"), obj.GetMemberValue("Name"));
            }
            Console.WriteLine("----------------------------");
            using (Session session = new Session()) {
                XPCollection collection = new XPCollection(session, myClassA);
                Console.WriteLine("Objects loaded. Total count: {0}", collection.Count);
                foreach (XPBaseObject obj in collection)
                {
                    Console.WriteLine("ID:\t{0}, Name:\t{1}", obj.GetMemberValue("ID"), obj.GetMemberValue("Name"));
                }
            }
            Console.WriteLine("----------------------------");
            Console.WriteLine("Press Enter to Exit");
            Console.ReadLine();
        }
コード例 #9
0
        public static void SetXpMemberProperty(string propertyName, object value, XPBaseObject dbObject, bool save) {
            if (propertyName.IndexOf(".", StringComparison.Ordinal) > -1) {
                XPMemberInfo member = dbObject.ClassInfo.GetMember(propertyName.Split(".".ToCharArray())[0]);
                object o = member.GetValue(dbObject);
                if (typeof(XPBaseObject).IsAssignableFrom(member.MemberType)) {
                    dbObject = o as XPBaseObject;
                    SetXpMemberProperty(propertyName.Substring(propertyName.IndexOf(".", StringComparison.Ordinal) + 1), value, dbObject, save);
                    return;
                }
                SetPropertyValue(o.GetType().GetProperty(propertyName.Substring(propertyName.IndexOf(".", StringComparison.Ordinal) + 1)), o,
                                 value);
                return;
            }
            XPMemberInfo xpMemberInfo = dbObject.ClassInfo.GetMember(propertyName);
            if (xpMemberInfo == null)
                throw new PropertyMissingException(dbObject.GetType().FullName, propertyName);
            xpMemberInfo.SetValue(dbObject,
                                  xpMemberInfo.Owner.ClassType.GetProperty(propertyName) == null
                                      ? value
                                      : ChangeType(value, xpMemberInfo.MemberType));
            if (save)
                dbObject.Save();

        }