Пример #1
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            try
            {
                _saveButton   = NamingContainer.FindControl(SaveButtonID) as Button;
                _deleteButton = NamingContainer.FindControl(DeleteButtonID) as Button;
                _contentTitle = NamingContainer.FindControl(ContentTitleID) as Label;
                var msgLabel = NamingContainer.FindControl(NoticeMessageID) as Label;
                _noticeMessage = new NoticeLabelAdapter(msgLabel, CssNotice, CssWarning);

                if (_saveButton != null)
                {
                    InitSaveButton();
                }
                if (_deleteButton != null)
                {
                    _deleteButton.Click += DeleteButton_Click;
                    GetRequestObject();
                }
            }
            catch (WebControlException ex)
            {
                AddWarning(ex.RelatedControl, ex.Message);
            }
            catch (Exception ex)
            {
                AddWarning(ex.Message);
            }
        }
Пример #2
0
        public void TestPage()
        {
            DbEntry.Create(typeof(User));
            var name = new TextBox();

            name.ID       = "user_name";
            name.Text     = "tom";
            name.CssClass = "test";
            var age = new TextBox();

            age.ID       = "user_age";
            age.Text     = "18";
            age.CssClass = "test";
            var label = new Label();

            label.CssClass = "msg";
            var page = new MyPage(name, age);

            page.Controls.Add(label);
            var msg = new NoticeLabelAdapter(label, "notice", "warning");
            var ctx = ModelContext.GetInstance(typeof(User));
            var vh  = new ValidateHandler();
            var obj = ctx.GetObject <User>(page, "parse error");

            ctx.ValidateSave(page, vh, obj, msg, "hello", "inWarning", () => obj.Save());
            Assert.AreEqual("test inWarning", name.CssClass);
            Assert.AreEqual("test", age.CssClass);
            Assert.AreEqual("msg warning", label.CssClass);
            Assert.AreEqual("<ul>\r\n<li>Invalid Field Name The length should be 6 to 8 but was 3.</li>\r\n</ul>\r\n", label.Text);

            name.Text = "tom456789";
            vh        = new ValidateHandler();
            obj       = ctx.GetObject <User>(page, "parse error");
            msg       = new NoticeLabelAdapter(label, "notice", "warning");
            ctx.ValidateSave(page, vh, obj, msg, "hello", "inWarning", () => obj.Save());
            Assert.AreEqual("test inWarning", name.CssClass);
            Assert.AreEqual("test", age.CssClass);
            Assert.AreEqual("msg warning", label.CssClass);
            Assert.AreEqual("<ul>\r\n<li>Invalid Field Name The length should be 6 to 8 but was 9.</li>\r\n</ul>\r\n", label.Text);

            try {
                name.Text = "tom4567";
                age.Text  = "";
                vh        = new ValidateHandler();
                msg       = new NoticeLabelAdapter(label, "notice", "warning");
                obj       = ctx.GetObject <User>(page, "Field [{0}] parse error{1}");
                ctx.ValidateSave(page, vh, obj, msg, "hello", "inWarning", () => obj.Save());
            } catch (WebControlException ex) {
                ctx.ResetInputCss(page, "inWarning");
                PageHelper.SetCtrlClass(ex.RelatedControl, "inWarning");
                msg.AddMessage(ex.Message);
                msg.ShowWarning();
            }
            Assert.AreEqual("test", name.CssClass);
            Assert.AreEqual("test inWarning", age.CssClass);
            Assert.AreEqual("msg warning", label.CssClass);
            Assert.AreEqual("<ul>\r\n<li>Field [TestField] parse error</li>\r\n</ul>\r\n", label.Text);

            name.Text = "tom4567";
            age.Text  = "20";
            vh        = new ValidateHandler();
            obj       = ctx.GetObject <User>(page, "parse error");
            msg       = new NoticeLabelAdapter(label, "notice", "warning");
            ctx.ValidateSave(page, vh, obj, msg, "hello", "inWarning", () => obj.Save());
            Assert.AreEqual("test", name.CssClass);
            Assert.AreEqual("test", age.CssClass);
            Assert.AreEqual("msg notice", label.CssClass);
            Assert.AreEqual("<ul>\r\n<li>hello</li>\r\n</ul>\r\n", label.Text);
        }