/// <summary> /// 从表单模板生成表单字段 /// 1.保存表单模板数据前调用! /// </summary> /// <returns></returns> public FormFieldCollection FetchItems() { //需要开发 FormFieldCollection ffc = new FormFieldCollection(); string resolvestr = this.Module.ToString(); string[] regstr = new string[] { "<input(.*?)title=\"(.*?)\"(.*?)name=\"(.*?)\"(.*?)/>", //input表单 "<input(.*?)name=\"(.*?)\"(.*?)title=\"(.*?)\"(.*?)/>", //input表单 "<textarea(.*?)title=\"(.*?)\"(.*?)name=\"(.*?)\"(.*?)>([\\s\\S]*?)</textarea>", //多行文本框 "<textarea(.*?)name=\"(.*?)\"(.*?)title=\"(.*?)\"(.*?)>([\\s\\S]*?)</textarea>", //多行文本框 "<select(.*?)title=\"(.*?)\"(.*?)name=\"(.*?)\"([\\s\\S]*?)</select>", //下拉列表 "<select(.*?)name=\"(.*?)\"(.*?)title=\"(.*?)\"([\\s\\S]*?)</select>", //下拉列表 "<img(.*?)title=\"(.*?)\"(.*?)name=\"(.*?)\"(.*?)/>", //图片 "<img(.*?)name=\"(.*?)\"(.*?)title=\"(.*?)\"(.*?)/>", //图片 "<button(.*?)title=\"(.*?)\"(.*?)name=\"(.*?)\"([\\s\\S]*?)</button>", //按钮 "<button(.*?)name=\"(.*?)\"(.*?)title=\"(.*?)\"([\\s\\S]*?)</button>" //按钮 }; for (int i = 0; i < regstr.Length; i++) { MatchCollection mc = Regex.Matches(resolvestr, regstr[i]); for (int j = 0; j < mc.Count; j++) { FormField ff = new FormField(); if (i % 2 == 0) { ff.Id = mc[j].Result("$4"); ff.Text = mc[j].Result("$2"); } else { ff.Id = mc[j].Result("$2"); ff.Text = mc[j].Result("$4"); } if (mc[j].Result("$3").IndexOf("datafld") > -1) { ff.Type = Regex.Match(mc[j].Result("$3"), "datafld=\"(.*?)\"").Result("$1"); } ffc.Add(ff); } } return(ffc); }
/// <summary> /// /// </summary> /// <param name="formFieldCollection"></param> /// <param name="errorMessage"></param> /// <param name="messageTitle"></param> /// <param name="messageSubject"></param> /// <param name="returnFieldColl"></param> /// <returns></returns> internal static bool CheckRequiredFields(FormFieldCollection formFieldCollection, out string errorMessage, out string messageTitle, out string messageSubject, out FormFieldCollection returnFieldColl) { //list form fields you want to validate here var requiredFields = "First Name,DOB,Place of Birth,Gender".Split(','); var result = true; errorMessage = ""; messageTitle = ""; messageSubject = ""; returnFieldColl = new FormFieldCollection(); foreach (string fieldName in requiredFields) { foreach (FormField formField in formFieldCollection) { if (fieldName.ToLower() == formField.FieldName.ToLower()) { bool found; //If the form field has no value we assume validation failed //If the form field has a value and the value = select item or --select-- we assume //a drop down list where no value has been selected by the user switch (formField.FieldValue.ToLower()) { case "select item": case "--select--": case "": found = false; break; default: found = true; break; } //Always set the RenderValidationError property to true|false if (!found) { if (errorMessage.Length > 0) { errorMessage += ","; } //turn on the validation error icon formField.RenderValidationError = true; returnFieldColl.Add(formField); errorMessage += fieldName; } else { //turn off the validation error icon formField.RenderValidationError = false; returnFieldColl.Add(formField); } } } } if (errorMessage.Length > 0) { errorMessage = errorMessage.Insert(0, "These fields have missing values: "); messageTitle = "Field validation error"; messageSubject = "Missing required fields"; result = false; } return(result); }