就当是一个新的设计模式!
页面上要控制很多元素的可见要只读,在实际工作中发现其具有很大的共性,抽取了该模型,美其名曰: 分权模式,它以分支的形式处理权限,其优点是,一实现了UI和业务处理相分离的效果,并且UI端明晰,二通用性强,三是每部分都很明确,相对独立,方便团队开发和调试。 (它和一些模式,肯定可能找到相似之处, 但不完全相同。)
Code
public class DocEditPower
{
/// <summary>
/// 是否可以编辑附件
/// </summary>
public bool CanEditAttachment { get; set; }
/// <summary>
/// 作废
/// </summary>
public bool CanEditCancel { get; set; }
/// <summary>
/// 打印
/// </summary>
public bool CanEditPrint { get; set; }
/// <summary>
/// 是否可以发文
/// </summary>
public bool CanEditSendDoc { get; set; }
}
/// <summary>
/// 是否拥有权限改(只考虑发文)
/// </summary>
/// <author>yxh</author>
/// <param name="DocID"></param>
/// <returns></returns>
public static DocEditPower DocCanEdit(string DocID)
{
DocEditPower retVal = new DocEditPower();
V_Doc_LastStep_Info lastProc = DbConfig.TheGateWay.Find<V_Doc_LastStep_Info>(
V_Doc_LastStep_Info._.DocID == DocID
);
retVal.CanEditPrint = CanEditPrint(lastProc);
//如果新建.只显示. 保存, ( 打印,返回)
//如果是起草.我是拟稿人. 显示,保存,发送.
if (lastProc == null)
{
if (DbConfig.TheGateWay.Exists<GW_WJ>(GW_WJ._.DocID == DocID && GW_WJ._.CreatorOID == SessionManage.GetOne(SessionKey.OID)))
{
retVal.CanEditAttachment = true;
}
return retVal;
}
//我是( 拟稿人, 或者是接收人),
if (IamDealer(lastProc) == false) return retVal;
UserRole myRole = User_Dept.GetMyFullRole();
retVal.CanEditAttachment = CanEditAttachment(lastProc);
retVal.CanEditCancel = CanEditCancel(lastProc);
retVal.CanEditSendDoc = CanEditSendDoc(lastProc, myRole);
return retVal;
}
/// <summary>
/// 我是否是处理双方.
/// </summary>
/// <param name="lastProc"></param>
/// <returns></returns>
public static bool IamDealer(V_Doc_LastStep_Info lastProc)
{
if (lastProc.CreatorOID != SessionManage.GetOne(SessionKey.OID) &&
lastProc.ReceiverOIDs.Contains(SessionManage.GetOne(SessionKey.OID)) == false
)
{
return false;
}
else
{
return true;
}
}
/// <summary>
/// 附件.
/// </summary>
/// <param name="lastProc"></param>
/// <returns></returns>
private static bool CanEditAttachment(V_Doc_LastStep_Info lastProc)
{
if (lastProc.DocState != SendState.Pigeonholing.ToString() &&
lastProc.DocState != SendState.Pigeonholed.ToString())
{
return true;
}
return false;
}
/// <summary>
/// 是否可以发文 .
/// </summary>
/// <param name="lastProc"></param>
/// <returns></returns>
private static bool CanEditSendDoc(V_Doc_LastStep_Info lastProc, UserRole myRole)
{
//我是发文人,并且. 当前状态是(正在发文,或已发文.)并且, 报送发,有值.
//自动化流程:内勤可以编号,套头,发文,归档。
//if ((myRole &= UserRole.DocSender) == UserRole.DocSender)
//{
// if (lastProc.DocState == SendState.Sending.ToString() ||
// lastProc.DocState == SendState.Sent.ToString())
// {
// if (DbConfig.TheGateWay.Exists<GW_SendDept>(GW_SendDept._.DocID == lastProc.DocID))
// {
// return true;
// }
// }
//}
if (AutoDoer(lastProc, myRole)) return true;
return false;
}
/// <summary>
/// 是否可以作废.
/// </summary>
/// <param name="lastProc"></param>
/// <returns></returns>
private static bool CanEditCancel(V_Doc_LastStep_Info lastProc)
{
//如果是管理员,可以。2008年8月15日。 于新海。
if (SessionManage.GetOne(SessionKey.OID) == "admin")
{
return true;
}
//当发文以后就不可以作废了. 并且只有 拟稿人或最大官可以作废.
if (lastProc.DocState == SendState.Sent.ToString() ||
lastProc.DocState == SendState.Pigeonholing.ToString() ||
lastProc.DocState == SendState.Pigeonholed.ToString())
{
return false;
}
if (lastProc.CreatorOID == SessionManage.GetOne(SessionKey.OID))
{
return true;
}
if (User_Dept.GetMinPIDUserForDoc(lastProc.DocID) == SessionManage.GetOne(SessionKey.OID))
{
return true;
}
return false;
}
public class DocEditPower
{
/// <summary>
/// 是否可以编辑附件
/// </summary>
public bool CanEditAttachment { get; set; }
/// <summary>
/// 作废
/// </summary>
public bool CanEditCancel { get; set; }
/// <summary>
/// 打印
/// </summary>
public bool CanEditPrint { get; set; }
/// <summary>
/// 是否可以发文
/// </summary>
public bool CanEditSendDoc { get; set; }
}
/// <summary>
/// 是否拥有权限改(只考虑发文)
/// </summary>
/// <author>yxh</author>
/// <param name="DocID"></param>
/// <returns></returns>
public static DocEditPower DocCanEdit(string DocID)
{
DocEditPower retVal = new DocEditPower();
V_Doc_LastStep_Info lastProc = DbConfig.TheGateWay.Find<V_Doc_LastStep_Info>(
V_Doc_LastStep_Info._.DocID == DocID
);
retVal.CanEditPrint = CanEditPrint(lastProc);
//如果新建.只显示. 保存, ( 打印,返回)
//如果是起草.我是拟稿人. 显示,保存,发送.
if (lastProc == null)
{
if (DbConfig.TheGateWay.Exists<GW_WJ>(GW_WJ._.DocID == DocID && GW_WJ._.CreatorOID == SessionManage.GetOne(SessionKey.OID)))
{
retVal.CanEditAttachment = true;
}
return retVal;
}
//我是( 拟稿人, 或者是接收人),
if (IamDealer(lastProc) == false) return retVal;
UserRole myRole = User_Dept.GetMyFullRole();
retVal.CanEditAttachment = CanEditAttachment(lastProc);
retVal.CanEditCancel = CanEditCancel(lastProc);
retVal.CanEditSendDoc = CanEditSendDoc(lastProc, myRole);
return retVal;
}
/// <summary>
/// 我是否是处理双方.
/// </summary>
/// <param name="lastProc"></param>
/// <returns></returns>
public static bool IamDealer(V_Doc_LastStep_Info lastProc)
{
if (lastProc.CreatorOID != SessionManage.GetOne(SessionKey.OID) &&
lastProc.ReceiverOIDs.Contains(SessionManage.GetOne(SessionKey.OID)) == false
)
{
return false;
}
else
{
return true;
}
}
/// <summary>
/// 附件.
/// </summary>
/// <param name="lastProc"></param>
/// <returns></returns>
private static bool CanEditAttachment(V_Doc_LastStep_Info lastProc)
{
if (lastProc.DocState != SendState.Pigeonholing.ToString() &&
lastProc.DocState != SendState.Pigeonholed.ToString())
{
return true;
}
return false;
}
/// <summary>
/// 是否可以发文 .
/// </summary>
/// <param name="lastProc"></param>
/// <returns></returns>
private static bool CanEditSendDoc(V_Doc_LastStep_Info lastProc, UserRole myRole)
{
//我是发文人,并且. 当前状态是(正在发文,或已发文.)并且, 报送发,有值.
//自动化流程:内勤可以编号,套头,发文,归档。
//if ((myRole &= UserRole.DocSender) == UserRole.DocSender)
//{
// if (lastProc.DocState == SendState.Sending.ToString() ||
// lastProc.DocState == SendState.Sent.ToString())
// {
// if (DbConfig.TheGateWay.Exists<GW_SendDept>(GW_SendDept._.DocID == lastProc.DocID))
// {
// return true;
// }
// }
//}
if (AutoDoer(lastProc, myRole)) return true;
return false;
}
/// <summary>
/// 是否可以作废.
/// </summary>
/// <param name="lastProc"></param>
/// <returns></returns>
private static bool CanEditCancel(V_Doc_LastStep_Info lastProc)
{
//如果是管理员,可以。2008年8月15日。 于新海。
if (SessionManage.GetOne(SessionKey.OID) == "admin")
{
return true;
}
//当发文以后就不可以作废了. 并且只有 拟稿人或最大官可以作废.
if (lastProc.DocState == SendState.Sent.ToString() ||
lastProc.DocState == SendState.Pigeonholing.ToString() ||
lastProc.DocState == SendState.Pigeonholed.ToString())
{
return false;
}
if (lastProc.CreatorOID == SessionManage.GetOne(SessionKey.OID))
{
return true;
}
if (User_Dept.GetMinPIDUserForDoc(lastProc.DocID) == SessionManage.GetOne(SessionKey.OID))
{
return true;
}
return false;
}
作者:NewSea 出处:http://newsea.cnblogs.com/
QQ,MSN:iamnewsea@hotmail.com 如无特别标记说明,均为NewSea原创,版权私有,翻载必纠。欢迎交流,转载,但要在页面明显位置给出原文连接。谢谢。 |