You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

383 lines
16 KiB
Plaintext

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Data;
using BP.En;
using BP.DA;
using BP.Port;
using BP.WF.Template;
namespace BP.WF
{
/// <summary>
/// 抄送工作逻辑
/// </summary>
public class WorkCC
{
public WebUserCopy webUser = null;
public WorkNode currWN = null;
public Int64 WorkID = 0;
/// <summary>
/// 构造WorkCC
/// </summary>
/// <param name="wn"></param>
/// <param name="ndFrom"></param>
/// <param name="webUser"></param>
public WorkCC(WorkNode userWN, WebUserCopy webUser)
{
this.currWN = userWN;
this.WorkID = this.currWN.WorkID;
this.webUser= webUser;
}
/// <summary>
/// 执行抄送.
/// </summary>
public void DoCC()
{
//查询出来到达的抄送节点.
Directions dirs = new Directions();
dirs.Retrieve(DirectionAttr.Node, currWN.HisNode.NodeID, DirectionAttr.NodeType, (int)NodeType.CCNode, DirectionAttr.Idx);
if (dirs.Count == 0)
return; //如果没有抄送节点,就不处理.
//定义容器集合,获得可以抄送的节点.
Nodes ccNodes = new Nodes();
foreach (Direction dir in dirs)
{
Conds conds = new Conds();
int i = conds.Retrieve(CondAttr.FK_Node, currWN.HisNode.NodeID,
CondAttr.ToNodeID, dir.ToNode, CondAttr.CondType, (int)CondType.Dir, CondAttr.Idx);
//判断是否通过.
if (i == 0 || conds.GenerResult(currWN.rptGe) == true)
{
Node ccNode = new Node();
ccNode.NodeID = dir.ToNode;
ccNodes.AddEntity(ccNode); //加入到集合.
continue;
}
}
if (ccNodes.Count == 0)
return;
//定义容器:需要多个规则把他们合并.
DataTable dtCCers = new DataTable();
dtCCers.Columns.Add("EmpNo");
dtCCers.Columns.Add("EmpName");
dtCCers.Columns.Add("CCNodeID");
dtCCers.Columns.Add("CCNodeName");
//执行cc
foreach (Node myCCNode in ccNodes)
{
//获得抄送规则集合.
CCRoles rols = new CCRoles();
rols.Retrieve(CCRoleAttr.NodeID, myCCNode.NodeID, "Idx");
string emps = "";
//遍历岗位规则集合.
foreach (CCRole rol in rols)
{
//获得抄送人的集合.
DataTable dt = GenerCCers(rol, this.currWN.rptGe, this.WorkID);
//把数据放进去.
foreach (DataRow dr in dt.Rows)
{
string empNo = dr[0].ToString();
if (DataType.IsNullOrEmpty(empNo) == true)
continue;
if (emps.Contains(empNo + ",") == false)
{
emps += empNo + ",";
//把他加入到集合里.
DataRow mydr = dtCCers.NewRow();
mydr[0] = empNo;
if (dt.Columns.Count == 2)
mydr[1] = dr[1].ToString();
//节点ID.
mydr[2] = rol.NodeID; //抄送的节点.
dtCCers.Rows.Add(mydr);
}
}
}
}
//写入数据dtCCers
CCList cc = new CCList();
Int64 fid = this.currWN.HisGenerWorkFlow.FID;
string flowNo = this.currWN.HisGenerWorkFlow.FK_Flow;
foreach (DataRow mydr in dtCCers.Rows)
{
string empNo = mydr[0].ToString();
string empName = mydr[1].ToString();
string nodeID = mydr[2].ToString();
string nodeName = mydr[3].ToString();
cc.CCTo = empNo;
cc.CCToName = empName;
cc.NodeID = this.currWN.HisNode.NodeID;
cc.NodeName = this.currWN.HisNode.Name;
cc.ToNodeID = this.currWN.HisNode.NodeID;
cc.ToNodeName = this.currWN.HisNode.Name;
cc.FID = fid;
cc.FK_Flow = flowNo;
cc.FlowName = this.currWN.HisGenerWorkFlow.FlowName;
cc.NodeID = this.currWN.HisNode.NodeID; //节点ID.
cc.Title = this.currWN.HisGenerWorkFlow.Title;
cc.WorkID = this.WorkID;
cc.MyPK = cc.WorkID+"_"+ cc.NodeID+"_"+cc.CCTo;
cc.OrgNo = webUser.OrgNo;
try
{
cc.Insert();
}catch (Exception ex)
{
}
}
}
/// <summary>
/// 获得人员
/// </summary>
/// <param name="rol"></param>
/// <param name="rpt"></param>
/// <param name="workid"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public DataTable GenerCCers(CCRole rol, Entity rpt, Int64 workid)
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("No", typeof(string)));
dt.Columns.Add(new DataColumn("Name", typeof(string)));
DataTable mydt = new DataTable();
///按照接受人规则计算.
if (rol.CCRoleExcType == CCRoleExcType.ByDeliveryWay)
{
Node toNode = new Node(rol.NodeID);
WorkNode toWn = new WorkNode(this.currWN.HisWork, toNode);
FindWorker fw = new FindWorker();
DataTable mydt1 = fw.DoIt(this.currWN.HisFlow,this.currWN, toWn);
return mydt1;
}
string sql = "";
if (rol.CCRoleExcType == CCRoleExcType.ByDepts)
{
/*如果抄送到部门. */
// sql = "SELECT A." + BP.Sys.Base.Glo.UserNo + ", A.Name FROM Port_Emp A, WF_CCDept B WHERE B.FK_Dept=A.FK_Dept AND B.FK_Node=" + this.NodeID;
sql = "SELECT A." + BP.Sys.Base.Glo.UserNo + ", A.Name FROM Port_Emp A WHERE A.FK_Dept IN (" + rol.EnIDs + ") ";
mydt = DBAccess.RunSQLReturnTable(sql);
foreach (DataRow mydr in mydt.Rows)
{
DataRow dr = dt.NewRow();
dr["No"] = mydr["No"];
dr["Name"] = mydr["Name"];
dt.Rows.Add(dr);
}
return dt;
}
if (rol.CCRoleExcType == CCRoleExcType.ByEmps)
{
/*如果抄送到人员. */
sql = "SELECT A." + BP.Sys.Base.Glo.UserNo + ", A.Name FROM Port_Emp A, WF_CCEmp B WHERE A." + BP.Sys.Base.Glo.UserNoWhitOutAS + "=B.FK_Emp AND B.FK_Node=" + rol.NodeID;
sql = "SELECT A." + BP.Sys.Base.Glo.UserNo + ", A.Name FROM Port_Emp A WHERE " + BP.Sys.Base.Glo.UserNo + " IN (" + rol.EnIDs + ") ";
mydt = DBAccess.RunSQLReturnTable(sql);
foreach (DataRow mydr in mydt.Rows)
{
DataRow dr = dt.NewRow();
dr["No"] = mydr["No"];
dr["Name"] = mydr["Name"];
dt.Rows.Add(dr);
}
return dt;
}
if (rol.CCRoleExcType == CCRoleExcType.ByStations)
{
if (rol.CCStaWay == WF.CCStaWay.StationOnly)
{
sql = "SELECT " + BP.Sys.Base.Glo.UserNo + ",Name FROM Port_Emp A, Port_DeptEmpStation B WHERE A.No= B.FK_Emp AND B.FK_Station IN (" + rol.EnIDs + ")";
mydt = DBAccess.RunSQLReturnTable(sql);
foreach (DataRow mydr in mydt.Rows)
{
DataRow dr = dt.NewRow();
dr["No"] = mydr["No"];
dr["Name"] = mydr["Name"];
dt.Rows.Add(dr);
}
return dt;
}
if (rol.CCStaWay == WF.CCStaWay.StationSmartCurrNodeWorker || rol.CCStaWay == WF.CCStaWay.StationSmartNextNodeWorker)
{
/*按角色智能计算*/
string deptNo = "";
if (rol.CCStaWay == WF.CCStaWay.StationSmartCurrNodeWorker)
deptNo = BP.Web.WebUser.FK_Dept;
else
deptNo = DBAccess.RunSQLReturnStringIsNull("SELECT FK_Dept FROM WF_GenerWorkerlist WHERE WorkID=" + workid + " AND IsEnable=1 AND IsPass=0", BP.Web.WebUser.FK_Dept);
//sql = "SELECT " + BP.Sys.Base.Glo.UserNo + ",Name FROM Port_Emp A, Port_DeptEmpStation B, WF_CCStation C WHERE A." + BP.Sys.Base.Glo.UserNoWhitOutAS + "=B.FK_Emp AND B.FK_Station=C.FK_Station AND C.FK_Node=" + this.NodeID + " AND B.FK_Dept='" + deptNo + "'";
sql = "SELECT " + BP.Sys.Base.Glo.UserNo + ",Name FROM Port_Emp A, Port_DeptEmpStation B, WHERE A." + BP.Sys.Base.Glo.UserNoWhitOutAS + "=B.FK_Emp AND B.FK_Station IN (" + rol.EnIDs + ") AND B.FK_Dept='" + deptNo + "'";
mydt = DBAccess.RunSQLReturnTable(sql);
foreach (DataRow mydr in mydt.Rows)
{
DataRow dr = dt.NewRow();
dr["No"] = mydr["No"];
dr["Name"] = mydr["Name"];
dt.Rows.Add(dr);
}
return dt;
}
if (rol.CCStaWay == WF.CCStaWay.StationAndDept)
{
throw new Exception("err@没有解析StationAndDept. ");
//sql = "SELECT " + BP.Sys.Base.Glo.UserNo + ",Name FROM Port_Emp A, Port_DeptEmpStation B, WF_CCStation C, WF_CCDept D WHERE A." + BP.Sys.Base.Glo.UserNoWhitOutAS + "=B.FK_Emp AND B.FK_Station=C.FK_Station AND A.FK_Dept=D.FK_Dept AND B.FK_Dept=D.FK_Dept AND C.FK_Node=" + this.NodeID + " AND D.FK_Node=" + this.NodeID;
sql = "SELECT " + BP.Sys.Base.Glo.UserNo + ",Name FROM Port_Emp A, Port_DeptEmpStation B, WF_CCStation C, WF_CCDept D WHERE A.No=B.FK_Emp AND B.FK_Station=C.FK_Station AND A.FK_Dept=D.FK_Dept AND B.FK_Dept=D.FK_Dept AND C.FK_Node=" + rol.NodeID + " AND D.FK_Node=" + rol.NodeID;
mydt = DBAccess.RunSQLReturnTable(sql);
foreach (DataRow mydr in mydt.Rows)
{
DataRow dr = dt.NewRow();
dr["No"] = mydr["No"];
dr["Name"] = mydr["Name"];
dt.Rows.Add(dr);
}
return dt;
}
if (rol.CCStaWay == CCStaWay.StationDeptUpLevelCurrNodeWorker ||
rol.CCStaWay == CCStaWay.StationDeptUpLevelNextNodeWorker)
{
// 求当事人的部门编号.
string deptNo = "";
if (rol.CCStaWay == CCStaWay.StationDeptUpLevelCurrNodeWorker)
deptNo = BP.Web.WebUser.FK_Dept;
if (rol.CCStaWay == CCStaWay.StationDeptUpLevelNextNodeWorker)
deptNo = DBAccess.RunSQLReturnStringIsNull("SELECT FK_Dept FROM WF_GenerWorkerlist WHERE WorkID=" + workid + " AND IsEnable=1 AND IsPass=0", webUser.DeptNo);
while (true)
{
BP.Port.Dept dept = new Dept(deptNo);
//sql = "SELECT " + BP.Sys.Base.Glo.UserNo + ",Name FROM Port_Emp A, Port_DeptEmpStation B, WF_CCStation C WHERE A." + BP.Sys.Base.Glo.UserNoWhitOutAS + "=B.FK_Emp AND B.FK_Station=C.FK_Station AND C.FK_Node=" + this.NodeID + " AND B.FK_Dept='" + deptNo + "'";
sql = "SELECT " + BP.Sys.Base.Glo.UserNo + ",Name FROM Port_Emp A, Port_DeptEmpStation B WHERE A.No=B.FK_Emp AND B.FK_Station IN (" + rol.EnIDs + ") AND B.FK_Dept='" + deptNo + "'";
mydt = DBAccess.RunSQLReturnTable(sql);
foreach (DataRow mydr in mydt.Rows)
{
DataRow dr = dt.NewRow();
dr["No"] = mydr["No"];
dr["Name"] = mydr["Name"];
dt.Rows.Add(dr);
}
if (dept.ParentNo == "0")
break;
deptNo = dept.ParentNo;
}
return dt;
}
}
if (rol.CCRoleExcType == CCRoleExcType.BySQLs)
{
sql = rol.EnIDs.Clone() as string;
sql = sql.Replace("@WebUser.No", webUser.No);
sql = sql.Replace("@WebUser.Name", webUser.Name);
sql = sql.Replace("@WebUser.FK_Dept", webUser.DeptNo);
if (sql.Contains("@") == true)
sql = BP.WF.Glo.DealExp(sql, rpt, null);
/*按照SQL抄送. */
mydt = DBAccess.RunSQLReturnTable(sql);
foreach (DataRow mydr in mydt.Rows)
{
DataRow dr = dt.NewRow();
dr["No"] = mydr["No"];
dr["Name"] = mydr["Name"];
dt.Rows.Add(dr);
}
return dt;
}
/**按照表单字段抄送*/
if (rol.CCRoleExcType == CCRoleExcType.ByFrmField)
{
if (DataType.IsNullOrEmpty(rol.EnIDs) == true)
throw new Exception("抄送规则自动抄送选择按照表单字段抄送没有设置抄送人员字段");
string[] attrs = rol.EnIDs.Split(',');
foreach (string attr in attrs)
{
string ccers = rpt.GetValStrByKey(attr);
if (DataType.IsNullOrEmpty(ccers) == false)
{
//判断该字段是否启用了pop返回值
sql = "SELECT Tag1 AS VAL FROM Sys_FrmEleDB WHERE RefPKVal=" + workid + " AND EleID='" + attr + "'";
DataTable dtVals = DBAccess.RunSQLReturnTable(sql);
string emps = "";
//获取接受人并格式化接受人,
if (dtVals.Rows.Count > 0)
{
foreach (DataRow dr in dtVals.Rows)
emps += dr[0].ToString() + ",";
}
else
{
emps = ccers;
}
//end判断该字段是否启用了pop返回值
emps = emps.Replace(" ", ""); //去掉空格.
if (DataType.IsNullOrEmpty(emps) == false)
{
/*如果包含,; 例如 zhangsan,张三;lisi,李四;*/
string[] ccemp = emps.Split(',');
foreach (string empNo in ccemp)
{
if (DataType.IsNullOrEmpty(empNo) == true)
continue;
Emp emp = new Emp();
emp.UserID = empNo;
if (emp.RetrieveFromDBSources() == 1)
{
DataRow dr = dt.NewRow();
dr["No"] = empNo;
dr["Name"] = emp.Name;
dt.Rows.Add(dr);
}
}
}
}
}
return dt;
}
throw new Exception("err@没有解析的设置." + rol.CCRoleExcType);
}
}
}