【?】获得当前工作流的状态

    最近在做一个文档的审批系统,由于系统非常简单,我也承担了其中的设计工作,这是我第一次为一个要实际运营的系统做数据库设计。设计的时候力求满足需求和简单,并没有考虑太多设计理念或力图让数据库设计得优美。在之后的编码过程中,我遇到了不少问题,其中很多我认为是数据库设计的不完善造成的,需要我进行一下反思。暂时没有时间做这个工作了,希望我回到实验室之后,可以再翻出这个系统来看一下。

      下面贴我写的200多行的判断当前流程状态的函数,个人感觉十分恶心。

      

View Code
    public string getFlowState(int applicationDocsID)
{
Documents.Model.ApplicationDocs modelApplicationDocs = bllAppDocs.GetModel(applicationDocsID);
Documents.Model.BoardProposal modelBoardProposal;

if (modelApplicationDocs.isSubmitToSecretary == null || !(bool)modelApplicationDocs.isSubmitTolLeader)
{
return "申请材料未提交";
}
else
{
if (modelApplicationDocs.appDocsNum == null)
{
return "申请材料已提交";
}
else
{
if (modelApplicationDocs.isSubmitTolLeader == null || !(bool)modelApplicationDocs.isSubmitTolLeader)
{
return "申请材料已登记";
}
else
{
if (modelApplicationDocs.isSubmitToMainDept == null || !(bool)modelApplicationDocs.isSubmitToMainDept)
{
return "主管领导批转申请材料";
}
else
{
if (modelApplicationDocs.isSubmitToWorker == null || !(bool)modelApplicationDocs.isSubmitToWorker)
{
return "主办部长批转申请材料";
}
else
{
if (modelApplicationDocs.isPassed == null)
{
return "承办人审批申请材料";
}
else
{
if (!modelApplicationDocs.isPassed)
{
return "承办人审核申请材料不通过";
}
else
{
int boardProposalID = bllBoardProp.getBroadPropMaxID(applicationDocsID);
modelBoardProposal = bllBoardProp.GetModel(boardProposalID);
if (modelBoardProposal.boardProposalDocID == null)
{
return "承办人审核申请材料通过";
}
else
{
if (modelBoardProposal.isSubmitToDept == null || !(bool)modelBoardProposal.isSubmitToDept)
{
return "承办人已提交董事会议案";
}
else
{
if (modelBoardProposal.deptIsPassed == null)
{
return "董事会议案已提交主办部长";
}
else
{
if (!(bool)modelBoardProposal.deptIsPassed)
{
return "董事会议案主办部长审核不通过";
}
else
{
if (modelBoardProposal.isSubmitToLeader == null || !(bool)modelBoardProposal.isSubmitToLeader)
{
return "董事会议案主办部长审核通过";
}
else
{
if (modelBoardProposal.leaderIsPassed == null)
{
return "董事会议案提交主管领导";
}
else
{
if (!(bool)modelBoardProposal.leaderIsPassed)
{
return "董事会议案主管领导审核不通过";
}
else
{
if (modelBoardProposal.isSubmitToBoard == null || !(bool)modelBoardProposal.isSubmitToBoard)
{
return "董事会议案主管领导审核通过";
}
else
{
if (modelBoardProposal.boardIsPassed == null)
{
return "董事会议案已提交董事会";
}
else
{
if (!(bool)modelBoardProposal.boardIsPassed)
{
return "董事会已否决";
}
else
{
int approvalDocsID = bllApprovalDocs.getApprovalDocsID(boardProposalID);
Documents.Model.ApprovalDocs modelApprovalDocs = bllApprovalDocs.GetModel(approvalDocsID);
if (modelApprovalDocs.isSubmitToWorker == null || !(bool)modelApprovalDocs.isSubmitToWorker)
{
return "企业提交审批材料";
}
else
{
if (modelApprovalDocs.isPassed == null)
{
return "审批材料已提交承办人";
}
else
{
if (!(bool)modelApprovalDocs.isPassed)
{
return "审批材料审核不通过";
}
else
{
int replyDocID = bllReplayDoc.getReplyDocMaxID(approvalDocsID);
Documents.Model.ReplayDoc modelReplyDoc = bllReplayDoc.GetModel(replyDocID);
if (modelReplyDoc.replyDocID == null)
{
return "审批材料审核通过";
}
else
{
if (modelReplyDoc.isSubmitToDept == null || !(bool)modelReplyDoc.isSubmitToDept)
{
return "承办人起草批复公文";
}
else
{
if (modelReplyDoc.deptIsPassed == null)
{
return "承办人提交批复公文";
}
else
{
if (!(bool)modelReplyDoc.deptIsPassed)
{
return "批复公文审核不通过";
}
else
{
if (modelReplyDoc.isSubmitToOtherDept == null || !(bool)modelReplyDoc.isSubmitToOtherDept)
{
return "主办部长批复公文审核通过";
}
else
{
DataSet otherDeptApproval = bllReplyDocDeptApproval.GetList("replyDocID ="+replyDocID);
if (otherDeptApproval == null)
{
return "批复公文已分送相关部长";
}
else
{
if (modelReplyDoc.isSubmitToAdmin == null || !(bool)modelReplyDoc.isSubmitToAdmin)
{
return "相关部长审核通过";
}
else
{
if (modelReplyDoc.adminIsPassed == null)
{
return "批复公文已提交行政办公室主任";
}
else
{
if (!(bool)modelReplyDoc.adminIsPassed)
{
return "批复公文行政办公室主任审核不通过";
}
else
{
if (modelReplyDoc.isSubmitToLeader == null || !(bool)modelReplyDoc.isSubmitToLeader)
{
return "批复公文行政办公室主任审核通过";
}
else
{
if (modelReplyDoc.leaderIsPassed == null)
{
return "批复公文已提交主管领导";
}
else
{
if (!(bool)modelReplyDoc.leaderIsPassed)
{
return "批复公文主管领导审核不通过";
}
else
{
if (modelReplyDoc.isSubmitSecretary == null || !(bool)modelReplyDoc.isSubmitSecretary)
{
return "批复公文主管领导审核通过";
}
else
{
return "行政办公室文秘编文号";
}
}

}
}
}

}
}
}
}
}
}
}
}

}
}
}

}
}
}

}
}
}
}
}
}
}
}
}
}
}
}
}
}

}


这段代码里包含了大量的分支,导致这段代码非常难读,并且测试的难度可想而知了。再看这段代码,我可以做一些优化,提取一些共有方法,但是我觉得根源还在于数据库,当前判断状态的方式不够简洁。希望我在以后的开发和学习当中注意一下此类的问题,可以改进。

posted @ 2011-12-17 15:08  明之道  阅读(450)  评论(0编辑  收藏  举报