Пример #1
0
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            var ss = StringHelper.SplitByCase(binder.Name);

            if (ss.Count % 2 == 0)
            {
                throw new DataException("FindBy need Cola(AndColb) format.");
            }
            if (((ss.Count + 1) >> 1) != args.Length)
            {
                throw new DataException("The args count doesn't match method call " + binder.Name + "");
            }
            Condition c = null;
            int       n = 0;

            for (int i = 0; i < ss.Count; i += 2)
            {
                c &= CK <T> .Field[ss[i]] == args[n++];
                if (i + 1 < ss.Count)
                {
                    if (ss[i + 1] != "And")
                    {
                        throw new DataException("FindBy need Cola(AndColb) format.");
                    }
                }
            }
            result = DbEntry.GetObject <T>(c);
            return(true);
        }
Пример #2
0
        public void Test3()
        {
            DbEntry.Delete <Unit>(WhereCondition.EmptyCondition);

            Unit u = DynamicObject.NewObject <Unit>("00001");

            u.Name      = "吨";
            u.CreatedBy = "Jacky";
            u.UpdatedBy = "Admin";

            DbEntry.Save(u);
            var u1 = DbEntry.GetObject <Unit>(u.UnitId);

            Assert.AreEqual(u1.UnitId, u.UnitId);

            u1.Name = "M3";
            DbEntry.Update(u1);

            Unit u2 = DynamicObject.NewObject <Unit>("00002");

            u2.Init("M3", "Admin");
            Assert.AreEqual("M3", u2.Name);
            DbEntry.Save(u2);

            Assert.AreEqual(2, DbEntry.From <Unit>().Where(WhereCondition.EmptyCondition).GetCount());
        }
Пример #3
0
        public void Test2()
        {
            //Role r = new Role() {
            //    Name = "Jacky",
            //    CreatedBy = "Admin",
            //    UpdatedBy = "Admin"
            //};
            Role r = Role.New();

            r.Name      = "Jacky";
            r.CreatedBy = "Admin";
            r.UpdatedBy = "Admin";

            DbEntry.Save(r);

            Role r1 = DbEntry.GetObject <Role>(r.Id);

            Assert.IsNotNull(r1);
            Assert.AreEqual("Admin", r1.CreatedBy);
            r1.Name = "Modified by jacky.";
            DbEntry.Update(r1);

            Role r2 = DbEntry.GetObject <Role>(r.Id);

            Assert.AreEqual("Modified by jacky.", r2.Name);
        }
Пример #4
0
        protected T GetRequestObject()
        {
            string sid = Page.Request["Id"];

            if (!string.IsNullOrEmpty(sid))
            {
                object id = ClassHelper.ChangeType(sid, Ctx.Info.KeyMembers[0].MemberType);
                var    o  = DbEntry.GetObject <T>(id);
                if (o == null)
                {
                    throw new DataException("The record doesn't exist.");
                }
                ViewState["Id"] = id;
                var ctx = ModelContext.GetInstance(typeof(T));
                if (ctx.Info.LockVersion != null)
                {
                    var lv = (int)ctx.Info.LockVersion.GetValue(o);
                    if (Page.IsPostBack)
                    {
                        if (lv != ObjectLockVersion)
                        {
                            throw new DataException("The version of record was changed.");
                        }
                    }
                    else
                    {
                        ObjectLockVersion = lv;
                    }
                }
                return(o);
            }
            return(default(T));
        }
Пример #5
0
        public void TestHasAndBelongsToMany()
        {
            var u = new cmmReader("Tom");

            u.arts.Add(new cmmArticle("do"));
            u.arts.Add(new cmmArticle("ok"));
            u.arts.Add(new cmmArticle("go"));
            DbEntry.Save(u);
            var a = DbEntry.GetObject <cmmArticle>(u.arts[2].Id);

            a.rads.Add(new cmmReader("Jerry"));
            a.rads[0].arts.Add(new cmmArticle("pp"));
            DbEntry.Save(a);
            var o1 = DbEntry.GetObject <cmmReader>(u.Id);

            Assert.AreEqual("Tom", o1.Name);
            Assert.AreEqual(3, o1.arts.Count);
            Assert.AreEqual("do", o1.arts[0].Title);
            Assert.AreEqual("ok", o1.arts[1].Title);
            Assert.AreEqual("go", o1.arts[2].Title);
            var o2 = DbEntry.GetObject <cmmReader>(a.rads[0].Id);

            Assert.AreEqual("Jerry", o2.Name);
            Assert.AreEqual(2, o2.arts.Count);
            Assert.AreEqual("go", o2.arts[0].Title);
            Assert.AreEqual("pp", o2.arts[1].Title);
        }
Пример #6
0
        public void Test2()
        {
            var o = DbEntry.GetObject <UnsignedPCReal>(1);

            Assert.AreEqual("IBM", o.Name);
            Assert.AreEqual(2, o.Person_Id);
        }
Пример #7
0
        public void TestLazyLoadColumn2()
        {
            DbEntry.GetObject <LazyableSqlite>(1);

            StaticRecorder.ClearMessages();
            StaticRecorder.CurRow.Clear();
            StaticRecorder.CurRow.Add(new RowInfo("Id", typeof(long), 2L));
            StaticRecorder.CurRow.Add(new RowInfo("Person_Id", typeof(int), 2));

            var o1 = DbEntry.GetObject <LazyableSqlite>(2);

            Assert.AreEqual(2, o1.TestColumn);

            var o2 = DbEntry.GetObject <LazyableSqlite>(2);

            Assert.AreEqual(2, o2.TestColumn);
            StaticRecorder.CurRow.Clear();
            StaticRecorder.CurRow.Add(new RowInfo("Name", typeof(string), "IBM"));
            Assert.AreEqual("IBM", o2.Content.Value);

            var o3 = DbEntry.GetObject <LazyableSqlite>(2);

            Assert.AreEqual(2, o3.TestColumn);
            StaticRecorder.CurRow.Clear();
            StaticRecorder.CurRow.Add(new RowInfo("Name", typeof(string), "IBM"));
            Assert.AreEqual("IBM", o3.Content.Value);

            Assert.AreEqual(3, StaticRecorder.Messages.Count);
        }
Пример #8
0
        public void TestPropertyClassImpl()
        {
            var o = DbEntry.GetObject <PropertyClassImpl>(1);

            Assert.IsNotNull(o);
            Assert.AreEqual("Tom", o.Name);
        }
Пример #9
0
        int IExcuteableDataSource.Delete(IDictionary keys, IDictionary values)
        {
            object key = ClassHelper.ChangeType(keys[KeyName], Ctx.Info.KeyMembers[0].MemberType);
            var    obj = DbEntry.GetObject <T>(key);

            return(ExecuteDelete(obj));
        }
Пример #10
0
        public void TestUniqueValidate()
        {
            var u = new UniquePerson {
                Name = "test"
            };
            var vh = new ValidateHandler();

            vh.ValidateObject(u);
            Assert.IsTrue(vh.IsValid);

            u.Name = "Tom";
            vh     = new ValidateHandler();
            vh.ValidateObject(u);
            Assert.IsFalse(vh.IsValid);
            Assert.AreEqual("Invalid Field Name Should be UNIQUED.", vh.ErrorMessages["Name"]);

            // smart validate
            var p = DbEntry.GetObject <UniquePerson>(1);
            var n = ConsoleMessageLogRecorder.Count;

            Assert.IsTrue(p.IsValid());
            Assert.AreEqual(n + 1, ConsoleMessageLogRecorder.Count);
            p.Name = "Jerry";
            Assert.IsFalse(p.IsValid());
            Assert.AreEqual(n + 2, ConsoleMessageLogRecorder.Count);
        }
Пример #11
0
        public void Test1()
        {
            var p = new SinglePerson {
                Name = "abc"
            };

            Assert.AreEqual(0, p.Id);

            DbEntry.Save(p);
            Assert.IsTrue(0 != p.Id);
            var p1 = DbEntry.GetObject <SinglePerson>(p.Id);

            Assert.AreEqual(p.Name, p1.Name);

            p.Name = "xyz";
            DbEntry.Save(p);
            Assert.AreEqual(p.Id, p1.Id);

            p1 = DbEntry.GetObject <SinglePerson>(p.Id);
            Assert.AreEqual("xyz", p1.Name);

            long id = p.Id;

            DbEntry.Delete(p);
            Assert.AreEqual(0, p.Id);
            p1 = DbEntry.GetObject <SinglePerson>(id);
            Assert.IsNull(p1);
        }
Пример #12
0
        int IBaseBLL.Delete(ND_USER user, IDictionary keys, IDictionary values)
        {
            object key = ClassHelper.ChangeType(keys[KeyName], Ctx.Info.KeyMembers[0].MemberType);
            var    obj = DbEntry.GetObject <T>(key);

            return(ExecuteDelete(user, obj));
        }
Пример #13
0
        public void TestHasMany9()
        {
            // If not loading B, and insert a new item in B, then don't loading, when save it, only save which in the memory
            var c = DbEntry.GetObject <Category>(2);
            var b = new Book {
                Name = "Next"
            };

            c.Books.Add(b);
            Assert.AreEqual(1, c.Books.Count);
            DbEntry.Save(c);

            // verify
            c = DbEntry.GetObject <Category>(2);
            Assert.IsNotNull(c);
            Assert.IsTrue(4 == c.Books.Count);

            Assert.AreEqual("Game", c.Name);
            Assert.AreEqual("Diablo", c.Books[0].Name);
            Assert.AreEqual(1, c.Books[0].Id);
            Assert.AreEqual("Pal95", c.Books[1].Name);
            Assert.AreEqual(4, c.Books[1].Id);
            Assert.AreEqual("Wow", c.Books[2].Name);
            Assert.AreEqual(5, c.Books[2].Id);
            Assert.AreEqual("Next", c.Books[3].Name);
            Assert.AreEqual(6, c.Books[3].Id);
        }
Пример #14
0
        private void DeleteButton_Click(object sender, EventArgs e)
        {
            _lastOprationSucceed = false;
            try
            {
                object oid = ViewState["Id"];

                string tn = typeof(T).Name;
                if (oid != null)
                {
                    var o = DbEntry.GetObject <T>(oid);
                    ExecuteDelete(o);
                    AddNotice(string.Format(ObjectDeletedText, tn));
                    _lastOprationSucceed = true;
                }
            }
            catch (WebControlException ex)
            {
                AddWarning(ex.RelatedControl, ex.Message);
            }
            catch (Exception ex)
            {
                AddWarning(ex.Message);
            }
        }
Пример #15
0
        public void Test9()
        {
            // A.Save, if A.B is loaded item and remove it from A, delete A_B
            var a = DbEntry.GetObject <Article>(1);

            Assert.AreEqual(3, a.Readers.Count);
            Assert.AreEqual("tom", a.Readers[0].Name);
            Assert.AreEqual("jerry", a.Readers[1].Name);
            Assert.AreEqual("mike", a.Readers[2].Name);

            a.Readers.RemoveAt(1);
            Assert.AreEqual(2, a.Readers.Count);
            Assert.AreEqual("tom", a.Readers[0].Name);
            Assert.AreEqual("mike", a.Readers[1].Name);

            DbEntry.Save(a);

            a = DbEntry.GetObject <Article>(1);
            Assert.AreEqual(2, a.Readers.Count);
            Assert.AreEqual("tom", a.Readers[0].Name);
            Assert.AreEqual("mike", a.Readers[1].Name);

            var r = DbEntry.GetObject <Reader>(2);

            Assert.IsNotNull(r);
            Assert.AreEqual("jerry", r.Name);
            Assert.AreEqual(1, r.Articles.Count);
            Assert.AreEqual("The world is float", r.Articles[0].Name);
        }
Пример #16
0
        public void TestHasOne10()
        {
            // B.Select will read A (LazyLoading*)
            var pc = DbEntry.GetObject <PersonalComputer>(2);

            Assert.IsNotNull(pc);
            Assert.IsNotNull(pc.Owner.Value);
            Assert.AreEqual("Mike", pc.Owner.Value.Name);
        }
Пример #17
0
        public void TestHasMany10()
        {
            // B.Select will read A (LazyLoading*)
            var c = DbEntry.GetObject <Book>(2);

            Assert.IsNotNull(c);
            Assert.IsNotNull(c.CurCategory.Value);
            Assert.AreEqual("Tour", c.CurCategory.Value.Name);
        }
Пример #18
0
        public void TestListClear2()
        {
            var c = DbEntry.GetObject <Category>(3);

            c.Books.Clear();
            DbEntry.Save(c);

            var c1 = DbEntry.GetObject <Category>(3);

            Assert.AreEqual(0, c1.Books.Count);
        }
Пример #19
0
        public void TestHasOne1_1()
        {
            // A.Select will read B (LazyLoading*), and set B.a as a
            var p = DbEntry.GetObject <Person>(2);

            Assert.IsNotNull(p);
            Assert.IsNotNull(p.PC.Value);
            Assert.AreEqual("Jerry", p.Name);
            p.Name = "Test";
            Assert.AreEqual("Test", p.PC.Value.Owner.Value.Name);
        }
Пример #20
0
        public void Test1()
        {
            // A.Select will load A, A.B will LazyLoading
            var a = DbEntry.GetObject <Article>(1);

            Assert.IsNotNull(a);
            Assert.AreEqual(3, a.Readers.Count);
            Assert.AreEqual("tom", a.Readers[0].Name);
            Assert.AreEqual("jerry", a.Readers[1].Name);
            Assert.AreEqual("mike", a.Readers[2].Name);
        }
Пример #21
0
        public void TestHasOne11()
        {
            // B.Select will read A (LazyLoading*), and set A.b as B
            var pc = DbEntry.GetObject <PersonalComputer>(2);

            Assert.IsNotNull(pc);
            Assert.IsNotNull(pc.Owner.Value);
            Assert.AreEqual("Mike", pc.Owner.Value.Name);
            pc.Name = "Test";
            Assert.AreEqual("Test", pc.Owner.Value.PC.Value.Name);
        }
Пример #22
0
        public void TestHasMany1A()
        {
            // A.Select will read B (LazyLoading*), and set B.a as A
            var c = DbEntry.GetObject <Category>(2);

            Assert.IsNotNull(c);
            Assert.IsTrue(3 == c.Books.Count);
            Assert.AreEqual("Game", c.Name);
            c.Name = "Sport";
            Assert.AreEqual("Sport", c.Books[0].CurCategory.Value.Name);
        }
Пример #23
0
        public void TestHasMany6()
        {
            // B has a foreign key A_id
            // B.a = A will set value of B.A_id
            // B.a = A will set A.a = b ????
            var c = DbEntry.GetObject <Category>(3);
            var b = new Book {
                Name = "Luoyang", CurCategory = { Value = c }
            };

            Assert.AreEqual(b.CurCategory.ForeignKey, 3);
        }
Пример #24
0
        public void TestHasOne1()
        {
            // A.Select will read B (LazyLoading*)
            var p = DbEntry.GetObject <Person>(2);

            Assert.IsNotNull(p);
            Assert.IsNotNull(p.PC.Value);

            Assert.AreEqual("Jerry", p.Name);
            Assert.AreEqual("IBM", p.PC.Value.Name);
            Assert.AreEqual(1, p.PC.Value.Id);
        }
Пример #25
0
        public void Test2()
        {
            // A.Select will load A, if A.B have been modified, then will not Loading B
            var a = DbEntry.GetObject <Article>(1);

            Assert.IsNotNull(a);
            a.Readers.Add(new Reader {
                Name = "ruby"
            });
            Assert.AreEqual(1, a.Readers.Count);
            Assert.AreEqual("ruby", a.Readers[0].Name);
        }
Пример #26
0
        public void TestHasOne8()
        {
            // B.Delete will delete itself
            var p = DbEntry.GetObject <Person>(2);

            Assert.IsNotNull(p);
            Assert.IsNotNull(p.PC.Value);
            DbEntry.Delete(p.PC.Value);
            p = DbEntry.GetObject <Person>(2);
            Assert.IsNotNull(p);
            Assert.IsNull(p.PC.Value);
        }
Пример #27
0
        public void TestDelteWillRemoveRelation()
        {
            // B.Delete() will cut the relation of it from A
            var a = DbEntry.GetObject <Article>(1);

            Assert.AreEqual(3, a.Readers.Count);
            a.Readers[0].Delete();
            a.Save();

            a = DbEntry.GetObject <Article>(1);
            Assert.AreEqual(2, a.Readers.Count);
        }
Пример #28
0
        public void TestRemoveSubItem()
        {
            var c = DbEntry.GetObject <Acategory>(2);

            Assert.AreEqual(3, c.Books.Count);

            c.Books.RemoveAt(1);
            DbEntry.Save(c);

            var c2 = DbEntry.GetObject <Acategory>(2);

            Assert.AreEqual(2, c2.Books.Count);
        }
Пример #29
0
        public void TestHasOne6()
        {
            // B has a foreign key  A_id
            // B.a = A will set the value of B.A_id
            // B.a = A will set A.a = b ????
            var p  = DbEntry.GetObject <Person>(3);
            var pc = new PersonalComputer();

            pc.Name        = "NewPC";
            pc.Owner.Value = p;

            Assert.AreEqual(pc.Owner.ForeignKey, 3);
        }
Пример #30
0
        public void TestHasMany11()
        {
            // B.Select will read A (LazyLoading*), and B.a.b[x] == B
            var c = DbEntry.GetObject <Book>(2);

            Assert.IsNotNull(c);
            Assert.AreEqual("Tour", c.CurCategory.Value.Name);
            Assert.AreEqual(2, c.CurCategory.Value.Books.Count);
            Assert.AreEqual("Beijing", c.CurCategory.Value.Books[0].Name);
            Assert.AreEqual("Shanghai", c.CurCategory.Value.Books[1].Name);
            c.Name = "Pingxiang";
            Assert.AreEqual("Pingxiang", c.CurCategory.Value.Books[0].Name);
        }