Example #1
0
        public void Test3()
        {
            var vh = new ValidateHandler(false);

            Assert.IsTrue(vh.ValidateObject(new vtest("12345", null, "[email protected]")));
            Assert.IsFalse(vh.ValidateObject(new vtest("123456", "", "[email protected]")));
        }
Example #2
0
        public static bool ValidateSave(Page p, ValidateHandler vh, object obj, NoticeLabel msg, string noticeText,
                                        string cssErrInput, Action callback)
        {
            var ctx = ModelContext.GetInstance(obj.GetType());

            EnumControls(p, ctx.Info, delegate(MemberHandler mh, WebControl c)
            {
                c.CssClass = "";
            });
            vh.ValidateObject(obj);
            if (vh.IsValid)
            {
                callback();
                if (msg != null)
                {
                    msg.AddNotice(noticeText);
                }
            }
            else
            {
                foreach (string str in vh.ErrorMessages.Keys)
                {
                    if (msg != null)
                    {
                        msg.AddWarning(vh.ErrorMessages[str]);
                    }
                    WebControl c = GetWebControl(p, ctx.Info, str);
                    if (c != null)
                    {
                        c.CssClass = cssErrInput;
                    }
                }
            }
            return(vh.IsValid);
        }
Example #3
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);
        }
Example #4
0
        public virtual ValidateHandler Validate()
        {
            var v = new ValidateHandler();

            v.ValidateObject(this);
            return(v);
        }
Example #5
0
 public static bool ValidateSave(this ModelContext ctx, Page p, ValidateHandler vh, object obj,
                                 NoticeLabelAdapter msg, string noticeText, string cssInputWarning, Action callback)
 {
     ctx.ResetInputCss(p, cssInputWarning);
     vh.ValidateObject(obj);
     if (vh.IsValid)
     {
         callback();
         if (msg != null)
         {
             msg.AddMessage(noticeText);
             msg.ShowNotice();
         }
     }
     else
     {
         vh.ErrorMessages.Keys
         .Map(key => GetWebControl(p, ctx.Info, key))
         .Filter(c => c != null)
         .Each(c => SetCtrlClass(c, cssInputWarning));
         if (msg != null)
         {
             vh.ErrorMessages.Keys.Each(key => msg.AddMessage(vh.ErrorMessages[key]));
             msg.ShowWarning();
         }
     }
     return(vh.IsValid);
 }
Example #6
0
        public void Test7()
        {
            var vh = new ValidateHandler(false, false, "{1}", "null", "match", "length", "unique", ", ");

            Assert.IsFalse(vh.ValidateObject(new vtest("lifeng", "beijing", "*****@*****.**")));
            Assert.AreEqual(1, vh.ErrorMessages.Count);
            Assert.AreEqual("length", vh.ErrorMessages["Name"]);
        }
Example #7
0
        public void Test4()
        {
            var vh = new ValidateHandler(false, false, "{1}", "", "", "", "", ", ");

            Assert.IsFalse(vh.ValidateObject(new vtest0("llf", "beijing", "aaa")));
            Assert.AreEqual(1, vh.ErrorMessages.Count);
            Assert.AreEqual("Please input valid email address", vh.ErrorMessages["Email"]);
        }
Example #8
0
        public void TestValidationOfBinaryAndBlob()
        {
            var o = new BinaryAndBLOB {
                password = new byte[] { 1 }, image = new byte[] {}
            };
            var vh      = new ValidateHandler();
            var isValid = vh.ValidateObject(o);

            Assert.IsFalse(isValid);

            o.password = new byte[] { 1, 2, 3, 4, 5, 6 };
            isValid    = vh.ValidateObject(o);
            Assert.IsFalse(isValid);

            o.password = new byte[] { 1, 2, 3, 4, 5 };
            isValid    = vh.ValidateObject(o);
            Assert.IsTrue(isValid);
        }
Example #9
0
        public void Test10()
        {
            var vh = new ValidateHandler(true);

            vh.ValidateObject(new vPeople1 {
                Name = ""
            });
            Assert.AreEqual(false, vh.IsValid);
            Assert.AreEqual("Invalid Field 测试 Not Allow Null.", vh.ErrorMessages["Name"]);
        }
Example #10
0
        public void Test9()
        {
            var vh = new ValidateHandler(false, false, "{1}", "null", "match", "length", "unique", ", ");

            Assert.IsFalse(vh.ValidateObject(new vPeople0 {
                Name = "Tom"
            }));
            Assert.AreEqual(1, vh.ErrorMessages.Count);
            Assert.AreEqual("unique", vh.ErrorMessages["Name"]);
        }
Example #11
0
 public virtual ValidateHandler Validate()
 {
     var v = new ValidateHandler();
     v.ValidateObject(this);
     return v;
 }
Example #12
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        StringBuilder errMsg = new StringBuilder();

        if (this.CurBmk != null)
        {
            string oldBmkJson = this.CurBmk.Json();
            this.CurBmk.bj = this.txtBj.Text.Trim();
            this.CurBmk.xh = this.txtBnbh.Text.Trim();
            if (IDCardChecker.CheckIDCard(this.txtsfzh.Text) && this.txtsfzh.Text != null)
            {
                if (this.txtsfzh.Text.Substring(6, 8) != this.txtCsny.Text)
                {
                    errMsg.Append("身份证号码中的出生年月日与你所填写的出生年月日不一致!");
                }
                string sexIDCard = this.txtsfzh.Text.Substring(16, 1);
                if ("02468Xx".Contains(sexIDCard) && (this.ddlSex.SelectedValue != "2"))
                {
                    errMsg.Append("身份证号码与所选性别不一致!");
                }
                else if ("13579".Contains(sexIDCard) && (this.ddlSex.SelectedValue != "1"))
                {
                    errMsg.Append("身份证号码与所选性别不一致!");
                }
                this.CurBmk.sfzh = this.txtsfzh.Text.Trim();
            }
            else
            {
                this.CurBmk.sfzh = this.txtsfzh.Text.Trim();//身份证错误也允许录入
                errMsg.Append("身份证号码已经保存但有错误!");
            }
            this.CurBmk.xstbh = this.txtXstbh.Text.Trim();
            this.CurBmk.xm    = this.txtXm.Text.Trim();
            this.CurBmk.Bm    = this.txtBm.Text.Trim();
            if (this.ddlSex.SelectedIndex > 0)
            {
                this.CurBmk.xb = this.ddlSex.SelectedValue;
            }
            else
            {
                errMsg.Append("性别没选择,");
            }

            if (Bmk.ValidateCsny(this.txtCsny.Text))
            {
                this.CurBmk.csny = this.txtCsny.Text.Trim();
            }
            else
            {
                errMsg.Append("出生年月日有误!必须是8位数字(如:19910805),");
            }

            if (this.ddlTy.SelectedIndex > 0)
            {
                this.CurBmk.ty = this.ddlTy.SelectedValue;//团员
            }
            else
            {
                errMsg.Append("是否团员未选择,");
            }

            if (this.ddlMz.SelectedIndex > 0)
            {
                this.CurBmk.mz = this.ddlMz.SelectedValue;//民族
            }
            else
            {
                errMsg.Append("民族未选择,");
            }

            if (this.ddlKslb.SelectedIndex > 0)
            {
                this.CurBmk.kslb = this.ddlKslb.SelectedValue;//考生类别
            }
            else
            {
                errMsg.Append("考生类别未选择,");
            }

            if (this.ddlHk.SelectedIndex > 0)
            {
                this.CurBmk.hk = this.ddlHk.SelectedValue;
            }
            else
            {
                errMsg.Append("户口未选择,");
            }

            if (this.txtTel.Text.IsNullOrEmpty())
            {
                errMsg.Append("联系电话未填写,");
            }
            else
            {
                this.CurBmk.tel = this.txtTel.Text.Trim();
            }

            if (this.txtJtzz.Text.IsNullOrEmpty())
            {
                errMsg.Append("家庭地址未填写,");
            }
            else
            {
                this.CurBmk.jtzz = this.txtJtzz.Text.Trim();
            }

            if (this.txtPost.Text.IsNullOrEmpty())
            {
                errMsg.Append("邮政编码未填写,");
            }
            else
            {
                this.CurBmk.post = this.txtPost.Text.Trim();
            }


            if (this.ddlSyqk.SelectedIndex > 0)
            {
                this.CurBmk.syqk = this.ddlSyqk.SelectedValue;
            }
            else
            {
                errMsg.Append("生源情况未选择,");
            }
            if (this.ddlHk.SelectedValue == "25" && this.ddlSyqk.SelectedValue != "0")
            {
                errMsg.Append("鹿城户籍学生只能选0,");
            }
            else if (this.ddlHk.SelectedValue != "25" && this.ddlSyqk.SelectedValue == "0")
            {
                errMsg.Append("非鹿城户籍学生只能选1或7,1表现在鹿城报考,7表示回原籍报考,报考幼师的同学只能回原籍报考,");
            }
            else if ("89".Contains(this.ddlSyqk.SelectedValue))
            {
                errMsg.Append("我们不能选择8或9,");
            }

            this.CurBmk.czhj = this.txtCzhj.Text.Trim();
            this.CurBmk.xqah = this.txtXqah.Text.Trim();

            this.CurBmk.father    = this.txtFather.Text.Trim();
            this.CurBmk.fatherdw  = this.txtFatherdw.Text.Trim();
            this.CurBmk.fatherzw  = this.txtFatherzw.Text.Trim();
            this.CurBmk.fathertel = this.txtFathertel.Text.Trim();
            this.CurBmk.mother    = this.txtMother.Text.Trim();
            this.CurBmk.motherdw  = this.txtMotherdw.Text.Trim();
            this.CurBmk.motherzw  = this.txtMotherzw.Text.Trim();
            this.CurBmk.mothertel = this.txtMothertel.Text.Trim();

            this.CurBmk.bz1 = this.txtBeizhu1.Text.Trim();
            this.CurBmk.bz2 = this.txtBeizhu2.Text.Trim();
            this.CurBmk.bz3 = this.txtBeizhu3.Text.Trim();
            this.CurBmk.bz4 = this.txtBeizhu4.Text.Trim();
            this.CurBmk.bz5 = this.txtBeizhu5.Text.Trim();
            this.CurBmk.bz6 = this.txtBeizhu6.Text.Trim();

            this.CurBmk.Bm = this.txtBm.Text.Trim();//别名

            //体测项目

            if (this.ddlTcxm1.SelectedIndex > 0 && this.ddlTcxm2.SelectedIndex > 0)
            {
                char tcxm1 = this.ddlTcxm1.SelectedValue[0];
                char tcxm2 = this.ddlTcxm2.SelectedValue[0];
                if (tcxm1 == tcxm2)
                {
                    errMsg.Append("体育两项选考必须不一样,");
                }
                else
                {
                    if (tcxm1 > tcxm2)
                    {
                        char temp = tcxm1;
                        tcxm1 = tcxm2;
                        tcxm2 = temp;
                    }
                    this.CurBmk.tcxm = tcxm1.ToString() + tcxm2.ToString();
                }
            }
            else
            {
                this.CurBmk.tcxm = "";
            }

            string byxxdm = this.txtByxxdm.Text;
            if (byxxdm.IsNullOrEmpty())
            {
                errMsg.Append("毕业学校代码未填写,");
            }
            else
            {
                string    dbfPath  = Server.MapPath("~/Data/Dbf/sysdbf/");
                string    dbfTable = "schools.DBF";
                DataTable dt       = DbfHelper.ToDataTable(dbfPath, dbfTable);
                var       rows     = dt.Select(string.Format("school = '{0}'", byxxdm));
                if (rows.Length == 1)
                {
                    this.CurBmk.byxxmc = rows[0]["mc"].ToString();
                    this.CurBmk.byxxdm = byxxdm;
                }
                else
                {
                    errMsg.Append("你所填写的就读学校代码有误");
                }
            }

            string newBmkJson = this.CurBmk.Json();
            if (newBmkJson == oldBmkJson)
            {
                JsUtil.MessageBox(this, "您没有改动任何数据!提示:" + errMsg.ToString());
            }
            else
            {
                ValidateHandler vh = new ValidateHandler(true);
                if (vh.ValidateObject(this.CurBmk))
                {
                    if (this.CurBmk.RecordGuid == Guid.Empty.ToString())
                    {
                        this.CurBmk.RecordGuid = Guid.NewGuid().ToString();
                    }
                    if (this.CurBmk.CurHistoryGuid == Guid.Empty.ToString())
                    {
                        this.CurBmk.CurHistoryGuid = Guid.NewGuid().ToString();
                    }
                    else
                    {
                        this.CurBmk.PreHistoryGuid = this.CurBmk.CurHistoryGuid;
                        this.CurBmk.CurHistoryGuid = Guid.NewGuid().ToString();
                    }
                    this.CurBmk.Save();
                    this.Save2File(this.CurBmk);
                    JsUtil.MessageBox(this, "数据保存成功!提示:" + errMsg.ToString());

                    BindData();
                }
                else
                {
                    JsUtil.MessageBox(this, "数据保存失败!提示:" + vh.ErrorMessages + errMsg.ToString());
                }
            }
        }
        else
        {
            throw new Exception("学生信息不存在!");
        }
    }
Example #13
0
        public void Test1()
        {
            var vh = new ValidateHandler(true);

            Assert.IsTrue(vh.ValidateObject(new vtest("12345", null, "[email protected]")), "1");
            Assert.IsFalse(vh.ValidateObject(new vtest("123456", null, "[email protected]")), "2");
            Assert.IsTrue(vh.ValidateObject(new vtest("测试1", null, "[email protected]")), "3");
            Assert.IsFalse(vh.ValidateObject(new vtest("测试一", null, "[email protected]")), "4");
            Assert.IsFalse(vh.ValidateObject(new vtest(null, null, "[email protected]")), "5");
            Assert.IsFalse(vh.ValidateObject(new vtest("", null, "[email protected]")), "6");
            Assert.IsTrue(vh.ValidateObject(new vtest("1", null, "[email protected]")), "7");

            Assert.IsTrue(vh.ValidateObject(new vtest("1", "", "[email protected]")), "8");
            Assert.IsTrue(vh.ValidateObject(new vtest("1", "12345678", "[email protected]")), "9");
            Assert.IsFalse(vh.ValidateObject(new vtest("1", "123456789", "[email protected]")), "10");
            Assert.IsTrue(vh.ValidateObject(new vtest("1", "测试测试测试测试", "[email protected]")), "11");
            Assert.IsFalse(vh.ValidateObject(new vtest("1", "测试测试测试测试1", "[email protected]")), "12");

            Assert.IsFalse(vh.ValidateObject(new vtest("1", null, "a.b.c")), "13");
            Assert.IsFalse(vh.ValidateObject(new vtest("1", null, null)), "14");
            Assert.IsFalse(vh.ValidateObject(new vtest("1", null, "")), "15");
            Assert.IsFalse(vh.ValidateObject(new vtest("1", null, "1")), "16");
        }
Example #14
0
        public void Test5()
        {
            var vh = new ValidateHandler(false);

            Assert.IsTrue(vh.ValidateObject(new vtest0("llf", "beijing", "*****@*****.**")));
        }
Example #15
0
        public void Test1()
        {
            var vh = new ValidateHandler(true);

            Assert.IsTrue(vh.ValidateObject(new vtest("12345", null, "[email protected]")));
            Assert.IsFalse(vh.ValidateObject(new vtest("123456", null, "[email protected]")));
            Assert.IsTrue(vh.ValidateObject(new vtest("测试1", null, "[email protected]")));
            Assert.IsFalse(vh.ValidateObject(new vtest("测试一", null, "[email protected]")));
            Assert.IsFalse(vh.ValidateObject(new vtest(null, null, "[email protected]")));
            Assert.IsFalse(vh.ValidateObject(new vtest("", null, "[email protected]")));
            Assert.IsTrue(vh.ValidateObject(new vtest("1", null, "[email protected]")));

            Assert.IsTrue(vh.ValidateObject(new vtest("1", "", "[email protected]")));
            Assert.IsTrue(vh.ValidateObject(new vtest("1", "12345678", "[email protected]")));
            Assert.IsFalse(vh.ValidateObject(new vtest("1", "123456789", "[email protected]")));
            Assert.IsTrue(vh.ValidateObject(new vtest("1", "测试测试测试测试", "[email protected]")));
            Assert.IsFalse(vh.ValidateObject(new vtest("1", "测试测试测试测试1", "[email protected]")));

            Assert.IsFalse(vh.ValidateObject(new vtest("1", null, "a.b.c")));
            Assert.IsFalse(vh.ValidateObject(new vtest("1", null, null)));
            Assert.IsFalse(vh.ValidateObject(new vtest("1", null, "")));
            Assert.IsFalse(vh.ValidateObject(new vtest("1", null, "1")));
        }