protected void Fail(Leafing.Data.ValidateHandler vh, string strMsg) { StringBuilder sb = new StringBuilder(); sb.AppendLine("<ul>"); foreach (var item in vh.ErrorMessages) { sb.AppendLine("<li>" + item.Value + "</li>"); } sb.AppendLine("</ul>"); this.MessageBox(sb.ToString()); }
protected void Save <T>(T dbEntityModel) where T : global::Leafing.Data.Definition.DbObjectModel <T, long>, new() { Leafing.Data.ValidateHandler vh = new Leafing.Data.ValidateHandler(); if (vh.ValidateObject(dbEntityModel)) { dbEntityModel.Save(); Succeed(); } else { string strMsg = string.Empty; Fail(vh, strMsg); } }
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("学生信息不存在!"); } }