工作流开发常用的表单验证
前台页面的JS代码:
<script type="text/javascript">
var CurrentTaskName = "<%=CurrentTaskName %>";
var SpecificationDisplay = "<%=SpecificationDisplay%>";
// 表单验证功能。已经默认加了表单验证,如需要额外增加表单验证功能,在页面定义此函数
function checkData() {
// 额外的判断,有些浏览器JS验证失败
return CheckHadCheck() && CheckMulTextBoxLength();
}
// 额外的判断,有些浏览器JS验证失败
function CheckHadCheck() {
if ($("[_tbApplyTitle]").val() == "") {
alert("申请单标题不能为空!");
return false;
}
if ($("[_txtExpression]").val() == "") {
alert("需求表达不能为空!");
return false;
}
var UrgencyDegree = false;
for (var i = 0; i < $("select[_ddlUrgencyDegree]")[0].length; i++) {
if ($("select[_ddlUrgencyDegree]")[0][i].selected) {
if ($("select[_ddlUrgencyDegree]")[0][i].selected) {
if ($("select[_ddlUrgencyDegree]")[0][i].innerHTML != "--请选择--") {
UrgencyDegree = true;
}
}
}
}
if (!UrgencyDegree) {
alert("紧急程度不能为空!");
return false;
}
var ESysType = false;
for (var i = 0; i < $("select[_ESysType]")[0].length; i++) {
if ($("select[_ESysType]")[0][i].selected) {
if ($("select[_ESysType]")[0][i].innerHTML != "--请选择--") {
ESysType = true;
}
}
}
if (!ESysType) {
alert("系统类别不能为空!");
return false;
}
var ppecification = $("[_Specification]").val();
if (CurrentTaskName == "实施") {
if ("" == ppecification) {
alert("实施情况说明不能为空!");
return false;
}
}
return true;
}
// 检测文本框输入最大长度
function CheckMulTextBoxLength() {
var MulTextBoxs = $("textarea[TextLength]");
if (MulTextBoxs) {
for (var i = 0; i < MulTextBoxs.length; i++) {
var tempMulTextBox = $(MulTextBoxs[i]);
if (tempMulTextBox.val().length > parseInt(tempMulTextBox.attr("TextLength"))) {
alert("【" + tempMulTextBox.attr("TextName") + "】" + "长度不能超过" + tempMulTextBox.attr("TextLength") + "个字符");
return false;
}
}
}
return true;
}
function CheckSelectedEmpty() {
var SelectedBox = $(".DDLCommon");
if (SelectedBox) {
for (var i = 0; i < SelectedBox.length; i++) {
var tempSelectedBox = $(SelectedBox[i]);
if (tempSelectedBox.children()[0].selected) {
alert(tempSelectedBox.attr("_ErrorText"));
return false;
}
}
}
return true;
}
$(document).ready(function () {
if (SpecificationDisplay == "true") {
$("#trSpecification").css("display", "block");
}
else {
$("#trSpecification").css("display", "none");
}
$.fn.selectReadOnly = function () {
var tem = $(this).children('option').index($("option:selected"));
$(this).change(function () {
$(this).children('option').eq(tem).attr("selected", true);
});
}
if (CurrentTaskName != "发起申请") {
$("[_ddlUrgencyDegree]").attr("disabled", "disabled");
$("[_ddlImportType]").attr("disabled", "disabled");
$("[_ddlSystemCatagory]").attr("disabled", "disabled");
$("[_ddlUrgencyDegree]").selectReadOnly();
$("[_ddlImportType]").selectReadOnly();
$("[_ddlSystemCatagory]").selectReadOnly();
$("[_tbApplyTitle]").attr("readonly", "readonly");
$("[_tbApplyTitle]").css("background", "#E5E5E5");
$("[_txtExpression]").attr("readonly", "readonly");
$("[_txtExpression]").css("background", "#E5E5E5");
$("[title='编辑']").css("display", "none");
$("[title='删除']").css("display", "none");
$(".toolbar").css("display", "none");
}
if (CurrentTaskName != "实施") {
$("[_Specification]").attr("readonly", "readonly");
$("[_Specification]").css("background", "#E5E5E5");
}
});
</script>
前台页面的html代码:
<tr>
<td>
<table cellpadding='2' cellspacing='1' class='ow_fim_mg' width='100%' id="formTabled">
<tr>
<td class='fi_l'>
工单标题:<font color='red'>*</font>
</td>
<td class='fi_r' colspan="3">
<asp:TextBox Width="83%" ID='tbApplyTitle' name="tbApplyTitle" _tbApplyTitle="True" runat='server'
required="" emptymsg="工单标题不能为空!" MaxLength="50"></asp:TextBox>
</td>
</tr>
<tr>
<td class='fi_l'>
申请单号:
</td>
<td class='fi_r'>
<asp:Label runat="server" ID="lblApplyCode"></asp:Label>
</td>
<td class='fi_l'>
工单类型:<font color='red'>*</font>
</td>
<td class='fi_r'>
<asp:Label runat="server" ID="lblAccountWorkOrderType"></asp:Label>
</td>
</tr>
<tr>
<td class='fi_l'>
申请人:
</td>
<td class='fi_r'>
<asp:Label ID="lblApplyUserName" runat="server"></asp:Label>
<asp:Label ID="lblApplyUserID" runat="server" style="display:none"></asp:Label>
</td>
<td class='fi_l'>
申请部门:
</td>
<td class='fi_r'>
<asp:Label ID="lblApplyOrgName" runat="server"></asp:Label>
<asp:Label ID="lblApplyOrgID" runat="server" style="display:none"></asp:Label>
</td>
</tr>
<tr>
<td class='fi_l'>
紧急程度:<font color='red'>*</font>
</td>
<td class='fi_r'>
<cc1:DDLCommon class="DDLCommon" _ErrorText="请选择紧急程度!" ID="ddlUrgencyDegree" runat="server" _ddlUrgencyDegree="True" EnumName="EEmergencyType" EmptyText="--请选择--"
IsEmptyText="true">
</cc1:DDLCommon>
</td>
<td class='fi_l'>
重要级别:
</td>
<td class='fi_r'>
<cc1:DDLCommon ID="ddlImportType" class="DDLCommon" runat="server" _ddlImportType=True
EnumName="EImportType" EmptyText="--请选择--" IsEmptyText="true">
</cc1:DDLCommon>
</td>
</tr>
<tr>
<td class='fi_l'>
系统类别:<font color='red'>*</font>
</td>
<td class='fi_r'>
<cc1:DDLCommon class="DDLCommon DDLSysType" _ErrorText="请选择系统类别!" ID="ddlSystemCatagory"
_EsysType="True" runat="server" EnumName="ESysType" _ddlSystemCatagory="True" EmptyText="--请选择--" Width="60%">
</cc1:DDLCommon>
</td>
<td class='fi_l'>
</td>
<td class='fi_r'>
</td>
</tr>
<tr>
<td class='fi_l'>
联系电话:
</td>
<td class='fi_r'>
<asp:Label ID="lblTelephone" runat="server"></asp:Label>
</td>
<td class='fi_l'>
申请时间:
</td>
<td class='fi_r'>
<asp:Label ID="lblApplyTime" runat="server" ></asp:Label>
</td>
</tr>
<tr>
<td class='fi_l'>
需求表达:<font color='red'>*</font>
</td>
<td class='fi_r' colspan="3">
<asp:TextBox TextMode="MultiLine" TextName="Expression" TextLength="250" ID='txtExpression' _txtExpression="True"
Width="83.5%" runat='server' Height="130" required=""
emptymsg="需求表达不能为空!"></asp:TextBox>
<br />
<label style="color:Red">需求表达最多250个字,详细问题描述,请上传附件说明。</label>
</td>
</tr>
<tr id="trSpecification">
<td class='fi_l'>
实施情况说明:<font color='red'>*</font>
</td>
<td class='fi_r' colspan="3">
<asp:TextBox TextMode="MultiLine" TextName="Specification" TextLength="250" ID='tbSpecification'
Width="83.5%" runat='server' _Specification="True" Height="130" ></asp:TextBox>
</td>
</tr>
</table>
</td>
</tr>
后台cs代码:
public string AccountType
{
get { return ViewState["AccountType"] == null ? string.Empty : ViewState["AccountType"].ToString(); }
set { ViewState["AccountType"] = value; }
}
public string CatagoryID
{
get { return ViewState["CatagoryID"] == null ? string.Empty : ViewState["CatagoryID"].ToString(); }
set { ViewState["CatagoryID"] = value; }
}
public string AccountWorkOrderID
{
get { return ViewState["AccountWorkOrderID"] == null ? string.Empty : ViewState["AccountWorkOrderID"].ToString(); }
set { ViewState["AccountWorkOrderID"] = value; }
}
/// <summary>
/// 实施安排和实施步骤显示表单信息
/// </summary>
public string SpecificationDisplay
{
get
{
if (CurrentTaskName == "实施" || CurrentTaskName == "复核" || CurrentTaskName == "验收")
{
return "true";
}
else
{
return "false";
}
}
}
/// <summary>
/// 获取当前步骤名称
/// </summary>
public string CurrentTaskName
{
get
{
return this.Workflow.InitWorkItem.TaskName;
}
}

浙公网安备 33010602011771号