Esempio n. 1
0
        /// <summary>
        /// 产生一个WorkNode
        /// </summary>
        /// <param name="fk_flow">流程编号</param>
        /// <param name="fk_node">节点ID</param>
        /// <param name="workID">工作ID</param>
        /// <param name="fid">FID</param>
        /// <param name="userNo">用户编号</param>
        /// <returns>返回dataset</returns>
        public static DataSet GenerWorkNode(string fk_flow, int fk_node, Int64 workID, Int64 fid, string userNo, string fromWorkOpt = "0")
        {
            //节点.
            if (fk_node == 0)
            {
                fk_node = int.Parse(fk_flow + "01");
            }

            if (workID == 0)
            {
                workID = BP.WF.Dev2Interface.Node_CreateBlankWork(fk_flow, null, null, userNo, null);
            }

            Node nd = new Node(fk_node);

            try
            {
                nd.WorkID = workID; //为获取表单ID提供参数.
                MapData md = new MapData();
                md.No = nd.NodeFrmID;
                if (md.RetrieveFromDBSources() == 0)
                {
                    throw new Exception("装载错误,该表单ID=" + md.No + "丢失,请修复一次流程重新加载一次.");
                }

                Work wk = nd.HisWork;
                wk.OID = workID;

                wk.RetrieveFromDBSources();
                wk.ResetDefaultVal();

                // 第1.2: 调用,处理用户定义的业务逻辑.
                string sendWhen = nd.HisFlow.DoFlowEventEntity(EventListOfNode.FrmLoadBefore, nd,
                                                               wk, null);

                //获得表单模版.
                DataSet myds = BP.Sys.CCFormAPI.GenerHisDataSet(md.No, nd.Name);

                //移除MapAttr
                myds.Tables.Remove("Sys_MapAttr"); //移除.

                //获取表单的mapAttr
                //求出集合.
                MapAttrs mattrs = new MapAttrs(md.No);
                if (fk_node != null)
                {
                    /*处理表单权限控制方案*/
                    FrmNode frmNode = new FrmNode();
                    int     count   = frmNode.Retrieve(FrmNodeAttr.FK_Frm, md.No, FrmNodeAttr.FK_Node, fk_node);
                    if (count != 0 && frmNode.FrmSln != 0)
                    {
                        FrmFields fls = new FrmFields(md.No, frmNode.FK_Node);
                        foreach (FrmField item in fls)
                        {
                            foreach (MapAttr attr in mattrs)
                            {
                                if (attr.KeyOfEn != item.KeyOfEn)
                                {
                                    continue;
                                }

                                if (item.IsSigan)
                                {
                                    item.UIIsEnable = false;
                                }

                                attr.UIIsEnable = item.UIIsEnable;
                                attr.UIVisible  = item.UIVisible;
                                attr.IsSigan    = item.IsSigan;
                                attr.DefValReal = item.DefVal;
                            }
                        }
                    }
                }

                DataTable Sys_MapAttr = mattrs.ToDataTableField("Sys_MapAttr");
                myds.Tables.Add(Sys_MapAttr);

                //把流程信息表发送过去.
                GenerWorkFlow gwf = new GenerWorkFlow();
                gwf.WorkID = workID;
                gwf.RetrieveFromDBSources();

                //加入WF_Node.
                DataTable WF_Node = nd.ToDataTableField("WF_Node");
                myds.Tables.Add(WF_Node);

                #region 加入组件的状态信息, 在解析表单的时候使用.
                BP.WF.Template.FrmNodeComponent fnc = new FrmNodeComponent(nd.NodeID);

                nd.WorkID = workID; //为获取表单ID提供参数.
                if (nd.NodeFrmID != "ND" + nd.NodeID && nd.HisFormType != NodeFormType.RefOneFrmTree)
                {
                    /*说明这是引用到了其他节点的表单,就需要把一些位置元素修改掉.*/
                    int refNodeID = int.Parse(nd.NodeFrmID.Replace("ND", ""));

                    BP.WF.Template.FrmNodeComponent refFnc = new FrmNodeComponent(refNodeID);

                    fnc.SetValByKey(FrmWorkCheckAttr.FWC_H, refFnc.GetValFloatByKey(FrmWorkCheckAttr.FWC_H));
                    fnc.SetValByKey(FrmWorkCheckAttr.FWC_W, refFnc.GetValFloatByKey(FrmWorkCheckAttr.FWC_W));
                    fnc.SetValByKey(FrmWorkCheckAttr.FWC_X, refFnc.GetValFloatByKey(FrmWorkCheckAttr.FWC_X));
                    fnc.SetValByKey(FrmWorkCheckAttr.FWC_Y, refFnc.GetValFloatByKey(FrmWorkCheckAttr.FWC_Y));

                    if (fnc.GetValFloatByKey(FrmWorkCheckAttr.FWC_H) <= 10)
                    {
                        fnc.SetValByKey(FrmWorkCheckAttr.FWC_H, 500);
                    }

                    if (fnc.GetValFloatByKey(FrmWorkCheckAttr.FWC_W) <= 10)
                    {
                        fnc.SetValByKey(FrmWorkCheckAttr.FWC_W, 600);
                    }

                    if (fnc.GetValFloatByKey(FrmWorkCheckAttr.FWC_X) <= 10)
                    {
                        fnc.SetValByKey(FrmWorkCheckAttr.FWC_X, 200);
                    }

                    if (fnc.GetValFloatByKey(FrmWorkCheckAttr.FWC_Y) <= 10)
                    {
                        fnc.SetValByKey(FrmWorkCheckAttr.FWC_Y, 200);
                    }


                    fnc.SetValByKey(FrmSubFlowAttr.SF_H, refFnc.GetValFloatByKey(FrmSubFlowAttr.SF_H));
                    fnc.SetValByKey(FrmSubFlowAttr.SF_W, refFnc.GetValFloatByKey(FrmSubFlowAttr.SF_W));
                    fnc.SetValByKey(FrmSubFlowAttr.SF_X, refFnc.GetValFloatByKey(FrmSubFlowAttr.SF_X));
                    fnc.SetValByKey(FrmSubFlowAttr.SF_Y, refFnc.GetValFloatByKey(FrmSubFlowAttr.SF_Y));

                    fnc.SetValByKey(FrmThreadAttr.FrmThread_H, refFnc.GetValFloatByKey(FrmThreadAttr.FrmThread_H));
                    fnc.SetValByKey(FrmThreadAttr.FrmThread_W, refFnc.GetValFloatByKey(FrmThreadAttr.FrmThread_W));
                    fnc.SetValByKey(FrmThreadAttr.FrmThread_X, refFnc.GetValFloatByKey(FrmThreadAttr.FrmThread_X));
                    fnc.SetValByKey(FrmThreadAttr.FrmThread_Y, refFnc.GetValFloatByKey(FrmThreadAttr.FrmThread_Y));

                    fnc.SetValByKey(FrmTrackAttr.FrmTrack_H, refFnc.GetValFloatByKey(FrmTrackAttr.FrmTrack_H));
                    fnc.SetValByKey(FrmTrackAttr.FrmTrack_W, refFnc.GetValFloatByKey(FrmTrackAttr.FrmTrack_W));
                    fnc.SetValByKey(FrmTrackAttr.FrmTrack_X, refFnc.GetValFloatByKey(FrmTrackAttr.FrmTrack_X));
                    fnc.SetValByKey(FrmTrackAttr.FrmTrack_Y, refFnc.GetValFloatByKey(FrmTrackAttr.FrmTrack_Y));

                    fnc.SetValByKey(FTCAttr.FTC_H, refFnc.GetValFloatByKey(FTCAttr.FTC_H));
                    fnc.SetValByKey(FTCAttr.FTC_W, refFnc.GetValFloatByKey(FTCAttr.FTC_W));
                    fnc.SetValByKey(FTCAttr.FTC_X, refFnc.GetValFloatByKey(FTCAttr.FTC_X));
                    fnc.SetValByKey(FTCAttr.FTC_Y, refFnc.GetValFloatByKey(FTCAttr.FTC_Y));

                    #region 没有审核组件分组就增加上审核组件分组. @杜需要翻译&测试.
                    if (md.HisFrmType == FrmType.FoolForm)
                    {
                        //判断是否是傻瓜表单,如果是,就要判断该傻瓜表单是否有审核组件groupfield ,没有的话就增加上.
                        DataTable gf     = myds.Tables["Sys_GroupField"];
                        bool      isHave = false;
                        foreach (DataRow dr in gf.Rows)
                        {
                            string cType = dr["CtrlType"] as string;
                            if (cType == null)
                            {
                                continue;
                            }

                            if (cType.Equals("FWC") == true)
                            {
                                isHave = true;
                            }
                        }

                        if (isHave == false)
                        {
                            DataRow dr = gf.NewRow();

                            nd.WorkID = workID; //为获取表单ID提供参数.
                            dr[GroupFieldAttr.OID]      = 100;
                            dr[GroupFieldAttr.FrmID]    = nd.NodeFrmID;
                            dr[GroupFieldAttr.CtrlType] = "FWC";
                            dr[GroupFieldAttr.CtrlID]   = "FWCND" + nd.NodeID;
                            dr[GroupFieldAttr.Idx]      = 100;
                            dr[GroupFieldAttr.Lab]      = "审核信息";
                            gf.Rows.Add(dr);

                            myds.Tables.Remove("Sys_GroupField");
                            myds.Tables.Add(gf);

                            //执行更新,就自动生成那个丢失的字段分组.
                            refFnc.Update();

                            /*
                             * //丢失了就插入新的.
                             * BP.Sys.GroupField gfEn = new GroupField();
                             * gfEn.FrmID = nd.NodeFrmID;
                             * gfEn.CtrlType = "FWC";
                             * gfEn.CtrlID = "FWCND" + nd.NodeID;
                             * gfEn.Idx = 100;
                             * gfEn.Lab = "审核信息";
                             * gfEn.Insert(); */
                        }
                    }
                    #endregion 没有审核组件分组就增加上审核组件分组.
                }

                #region 没有审核组件分组就增加上审核组件分组. @杜需要翻译&测试.
                if (nd.NodeFrmID == "ND" + nd.NodeID && nd.HisFormType != NodeFormType.RefOneFrmTree)
                {
                    //   Work wk1 = nd.HisWork;

                    if (nd.FormType == NodeFormType.FoolForm)
                    {
                        //判断是否是傻瓜表单,如果是,就要判断该傻瓜表单是否有审核组件groupfield ,没有的话就增加上.
                        DataTable gf     = myds.Tables["Sys_GroupField"];
                        bool      isHave = false;
                        foreach (DataRow dr in gf.Rows)
                        {
                            string cType = dr["CtrlType"] as string;
                            if (cType == null)
                            {
                                continue;
                            }

                            if (cType.Equals("FWC") == true)
                            {
                                isHave = true;
                            }
                        }

                        if (isHave == false)
                        {
                            DataRow dr = gf.NewRow();

                            nd.WorkID = workID; //为获取表单ID提供参数.
                            dr[GroupFieldAttr.OID]      = 100;
                            dr[GroupFieldAttr.FrmID]    = nd.NodeFrmID;
                            dr[GroupFieldAttr.CtrlType] = "FWC";
                            dr[GroupFieldAttr.CtrlID]   = "FWCND" + nd.NodeID;
                            dr[GroupFieldAttr.Idx]      = 100;
                            dr[GroupFieldAttr.Lab]      = "审核信息";
                            gf.Rows.Add(dr);

                            myds.Tables.Remove("Sys_GroupField");
                            myds.Tables.Add(gf);

                            //更新,为了让其自动增加审核分组.
                            BP.WF.Template.FrmNodeComponent refFnc = new FrmNodeComponent(nd.NodeID);
                            refFnc.Update();
                        }
                    }
                }
                #endregion 没有审核组件分组就增加上审核组件分组.

                myds.Tables.Add(fnc.ToDataTableField("WF_FrmNodeComponent"));

                #endregion 加入组件的状态信息, 在解析表单的时候使用.

                #region 增加 groupfields
                if (nd.FormType == NodeFormType.FoolTruck && nd.IsStartNode == false &&
                    DataType.IsNullOrEmpty(wk.HisPassedFrmIDs) == false)
                {
                    #region 处理字段分组排序.
                    //查询所有的分组, 如果是查看表单的方式,就不应该把当前的表单显示出来.
                    string myFrmIDs = "";
                    if (fromWorkOpt.Equals("1") == true)
                    {
                        if (gwf.WFState == WFState.Complete)
                        {
                            myFrmIDs = wk.HisPassedFrmIDs + ",'ND" + fk_node + "'";
                        }
                        else
                        {
                            myFrmIDs = wk.HisPassedFrmIDs; //流程未完成并且是查看表单的情况.
                        }
                    }
                    else
                    {
                        myFrmIDs = wk.HisPassedFrmIDs + ",'ND" + fk_node + "'";
                    }

                    GroupFields gfs = new GroupFields();
                    gfs.RetrieveIn(GroupFieldAttr.FrmID, "(" + myFrmIDs + ")");

                    //按照时间的顺序查找出来 ids .
                    string sqlOrder = "SELECT OID FROM  Sys_GroupField WHERE   FrmID IN (" + myFrmIDs + ")";
                    if (BP.Sys.SystemConfig.AppCenterDBType == DBType.Oracle)
                    {
                        myFrmIDs  = myFrmIDs.Replace("'", "");
                        sqlOrder += " ORDER BY INSTR('" + myFrmIDs + "',FrmID) , Idx";
                    }

                    if (BP.Sys.SystemConfig.AppCenterDBType == DBType.MSSQL)
                    {
                        myFrmIDs  = myFrmIDs.Replace("'", "");
                        sqlOrder += " ORDER BY CHARINDEX(FrmID, '" + myFrmIDs + "'), Idx";
                    }

                    if (BP.Sys.SystemConfig.AppCenterDBType == DBType.MySQL)
                    {
                        myFrmIDs  = myFrmIDs.Replace("'", "");
                        sqlOrder += " ORDER BY INSTR('" + myFrmIDs + "', FrmID ), Idx";
                    }
                    DataTable dtOrder = DBAccess.RunSQLReturnTable(sqlOrder);

                    //创建容器,把排序的分组放入这个容器.
                    GroupFields gfsNew = new GroupFields();

                    //遍历查询出来的分组.
                    foreach (DataRow dr in dtOrder.Rows)
                    {
                        string pkOID = dr[0].ToString();
                        var    mygf  = gfs.GetEntityByKey(pkOID);
                        gfsNew.AddEntity(mygf); //把分组字段加入里面去.
                    }

                    DataTable dtGF = gfsNew.ToDataTableField("Sys_GroupField");
                    myds.Tables.Remove("Sys_GroupField");
                    myds.Tables.Add(dtGF);
                    #endregion 处理字段分组排序.

                    #region 处理 mapattrs
                    //求当前表单的字段集合.
                    MapAttrs    attrs = new MapAttrs();
                    QueryObject qo    = new QueryObject(attrs);
                    qo.AddWhere(MapAttrAttr.FK_MapData, "ND" + nd.NodeID);
                    qo.addOrderBy(MapAttrAttr.Idx);
                    qo.DoQuery();

                    //计算累加的字段集合.
                    MapAttrs attrsLeiJia = new MapAttrs();
                    qo = new QueryObject(attrsLeiJia);
                    qo.AddWhere(MapAttrAttr.FK_MapData, " IN ", "(" + wk.HisPassedFrmIDs + ")");
                    qo.addOrderBy(MapAttrAttr.Idx);
                    qo.DoQuery();

                    //把两个集合接起来.
                    foreach (MapAttr item in attrsLeiJia)
                    {
                        item.UIIsEnable = false; //设置为只读的.
                        attrs.AddEntity(item);
                    }

                    //替换掉现有的.
                    myds.Tables.Remove("Sys_MapAttr");                      //移除.
                    myds.Tables.Add(attrs.ToDataTableField("Sys_MapAttr")); //增加.
                    #endregion 处理mapattrs

                    #region 把枚举放入里面去.
                    myds.Tables.Remove("Sys_Enum");

                    myFrmIDs = wk.HisPassedFrmIDs + ",'ND" + fk_node + "'";
                    SysEnums enums = new SysEnums();
                    enums.RetrieveInSQL(SysEnumAttr.EnumKey,
                                        "SELECT UIBindKey FROM Sys_MapAttr WHERE FK_MapData in(" + myFrmIDs + ")");

                    // 加入最新的枚举.
                    myds.Tables.Add(enums.ToDataTableField("Sys_Enum"));
                    #endregion 把枚举放入里面去.

                    #region  MapExt .
                    myds.Tables.Remove("Sys_MapExt");

                    // 把扩展放入里面去.
                    myFrmIDs = wk.HisPassedFrmIDs + ",'ND" + fk_node + "'";
                    BP.Sys.MapExts exts = new MapExts();
                    qo = new QueryObject(exts);
                    qo.AddWhere(MapExtAttr.FK_MapData, " IN ", "(" + myFrmIDs + ")");
                    qo.DoQuery();

                    // 加入最新的MapExt.
                    myds.Tables.Add(exts.ToDataTableField("Sys_MapExt"));
                    #endregion  MapExt .
                }
                #endregion 增加 groupfields

                #region 流程设置信息.
                if (nd.IsStartNode == false)
                {
                    BP.WF.Dev2Interface.Node_SetWorkRead(fk_node, workID);

                    // @杜.
                    if (gwf.TodoEmps.Contains(BP.Web.WebUser.Name + ";") == false)
                    {
                        gwf.TodoEmps += BP.Web.WebUser.No + "," + BP.Web.WebUser.Name;
                        gwf.Update();
                    }
                }

                //增加转向下拉框数据.
                if (nd.CondModel == CondModel.SendButtonSileSelect)
                {
                    if (nd.IsStartNode == true || gwf.TodoEmps.Contains(WebUser.No + ",") == true)
                    {
                        /*如果当前不是主持人,如果不是主持人,就不让他显示下拉框了.*/

                        /*如果当前节点,是可以显示下拉框的.*/
                        Nodes nds = nd.HisToNodes;

                        DataTable dtToNDs = new DataTable();
                        dtToNDs.TableName = "ToNodes";
                        dtToNDs.Columns.Add("No", typeof(string));           //节点ID.
                        dtToNDs.Columns.Add("Name", typeof(string));         //到达的节点名称.
                        dtToNDs.Columns.Add("IsSelectEmps", typeof(string)); //是否弹出选择人的对话框?
                        dtToNDs.Columns.Add("IsSelected", typeof(string));   //是否选择?

                        #region 增加到达延续子流程节点。
                        NodeYGFlows ygflows = new NodeYGFlows(fk_node.ToString());
                        if (ygflows.Count > 1 && SystemConfig.CustomerNo.Equals("CZBank") == true)
                        {
                            dtToNDs.Rows.Clear();  //为浙商银行做的特殊判断,如果配置了延续流程,就不让其走分支节点.
                        }
                        foreach (NodeYGFlow item in ygflows)
                        {
                            DataRow dr = dtToNDs.NewRow();
                            dr["No"]   = item.FK_Flow + "01";
                            dr["Name"] = "启动:" + item.FlowName;
                            //if (item.HisDeliveryWay == DeliveryWay.BySelected)
                            dr["IsSelectEmps"] = "1";
                            //else
                            //  dr["IsSelectEmps"] = "0";  //是不是,可以选择接受人.

                            //设置默认选择的节点.
                            //if (defalutSelectedNodeID == item.NodeID)
                            //    dr["IsSelected"] = "1";
                            //else
                            //    dr["IsSelected"] = "0";

                            dr["IsSelected"] = "0";
                            dtToNDs.Rows.Add(dr);
                        }
                        #endregion 增加到达延续子流程节点。

                        #region 到达其他节点.
                        //上一次选择的节点.
                        int defalutSelectedNodeID = 0;
                        if (nds.Count > 1)
                        {
                            string mysql = "";
                            // 找出来上次发送选择的节点.
                            if (SystemConfig.AppCenterDBType == DBType.MSSQL)
                            {
                                mysql = "SELECT  top 1 NDTo FROM ND" + int.Parse(nd.FK_Flow) + "Track A WHERE A.NDFrom=" + fk_node + " AND ActionType=1 ORDER BY WorkID DESC";
                            }
                            else if (SystemConfig.AppCenterDBType == DBType.Oracle)
                            {
                                mysql = "SELECT * FROM ( SELECT  NDTo FROM ND" + int.Parse(nd.FK_Flow) + "Track A WHERE A.NDFrom=" + fk_node + " AND ActionType=1 ORDER BY WorkID DESC ) WHERE ROWNUM =1";
                            }
                            else if (SystemConfig.AppCenterDBType == DBType.MySQL)
                            {
                                mysql = "SELECT  NDTo FROM ND" + int.Parse(nd.FK_Flow) + "Track A WHERE A.NDFrom=" + fk_node + " AND ActionType=1 ORDER BY WorkID  DESC limit 1,1";
                            }

                            //获得上一次发送到的节点.
                            defalutSelectedNodeID = DBAccess.RunSQLReturnValInt(mysql, 0);
                        }

                        #region 为天业集团做一个特殊的判断.
                        if (SystemConfig.CustomerNo == "TianYe" && nd.Name.Contains("董事长") == true)
                        {
                            /*如果是董事长节点, 如果是下一个节点默认的是备案. */
                            foreach (Node item in nds)
                            {
                                if (item.Name.Contains("备案") == true && item.Name.Contains("待") == false)
                                {
                                    defalutSelectedNodeID = item.NodeID;
                                    break;
                                }
                            }
                        }
                        #endregion 为天业集团做一个特殊的判断.


                        foreach (Node item in nds)
                        {
                            DataRow dr = dtToNDs.NewRow();
                            dr["No"]   = item.NodeID;
                            dr["Name"] = item.Name;
                            //if (item.hissel

                            if (item.HisDeliveryWay == DeliveryWay.BySelected)
                            {
                                dr["IsSelectEmps"] = "1";
                            }
                            else
                            {
                                dr["IsSelectEmps"] = "0";  //是不是,可以选择接受人.
                            }
                            //设置默认选择的节点.
                            if (defalutSelectedNodeID == item.NodeID)
                            {
                                dr["IsSelected"] = "1";
                            }
                            else
                            {
                                dr["IsSelected"] = "0";
                            }

                            dtToNDs.Rows.Add(dr);
                        }
                        #endregion 到达其他节点。


                        //增加一个下拉框, 对方判断是否有这个数据.
                        myds.Tables.Add(dtToNDs);
                    }
                }

                // 节点数据.
                //string sql = "SELECT * FROM WF_Node WHERE NodeID=" + fk_node;
                //DataTable dt = BP.DA.DBAccess.RunSQLReturnTable(sql);
                //dt.TableName = "WF_NodeBar";
                //myds.Tables.Add(dt);

                //// 流程数据.
                //Flow fl = new Flow(fk_flow);
                //myds.Tables.Add(fl.ToDataTableField("WF_Flow"));
                #endregion 流程设置信息.

                #region 把主从表数据放入里面.
                //.工作数据放里面去, 放进去前执行一次装载前填充事件.

                //重设默认值.
                wk.ResetDefaultVal();

                //@樊雷伟 把这部分代码搬到jflow上去. CCFlowAPI. 114行出.
                if (BP.Sys.SystemConfig.IsBSsystem == true)
                {
                    // 处理传递过来的参数。
                    foreach (string k in System.Web.HttpContext.Current.Request.QueryString.AllKeys)
                    {
                        if (DataType.IsNullOrEmpty(k) == true)
                        {
                            continue;
                        }

                        wk.SetValByKey(k, System.Web.HttpContext.Current.Request.QueryString[k]);
                    }

                    // 处理传递过来的frm参数。
                    foreach (string k in System.Web.HttpContext.Current.Request.Form.AllKeys)
                    {
                        if (DataType.IsNullOrEmpty(k) == true)
                        {
                            continue;
                        }
                        wk.SetValByKey(k, System.Web.HttpContext.Current.Request.Form[k]);
                    }

                    //更新到数据库里.
                    wk.DirectUpdate();
                }

                // 执行表单事件..
                string msg = md.DoEvent(FrmEventList.FrmLoadBefore, wk);
                if (DataType.IsNullOrEmpty(msg) == false)
                {
                    throw new Exception("err@错误:" + msg);
                }

                // 执行FEE事件.
                string msgOfLoad = nd.HisFlow.DoFlowEventEntity(EventListOfNode.FrmLoadBefore, nd,
                                                                wk, null);
                if (msgOfLoad != null)
                {
                    wk.RetrieveFromDBSources();
                }

                //执行装载填充.
                MapExt me = new MapExt();
                if (me.Retrieve(MapExtAttr.ExtType, MapExtXmlList.PageLoadFull, MapExtAttr.FK_MapData, wk.NodeFrmID) == 1)
                {
                    //执行通用的装载方法.
                    MapAttrs attrs = new MapAttrs(wk.NodeFrmID);
                    MapDtls  dtls  = new MapDtls(wk.NodeFrmID);
                    wk = BP.WF.Glo.DealPageLoadFull(wk, me, attrs, dtls) as Work;
                }

                //如果是累加表单,就把整个rpt数据都放入里面去.
                if (nd.FormType == NodeFormType.FoolTruck && nd.IsStartNode == false &&
                    DataType.IsNullOrEmpty(wk.HisPassedFrmIDs) == false)
                {
                    GERpt rpt = new GERpt("ND" + int.Parse(nd.FK_Flow) + "Rpt", workID); // nd.HisFlow.HisGERpt;
                    rpt.ResetDefaultVal();

                    //rpt.Copy(wk); //加入后就出现了错误.

                    myds.Tables.Add(rpt.ToDataTableField("MainTable"));
                    // myds.WriteXml("C:\\XX.xml");
                }
                else
                {
                    DataTable mainTable = wk.ToDataTableField(md.No);
                    mainTable.TableName = "MainTable";
                    myds.Tables.Add(mainTable);
                }
                string    sql = "";
                DataTable dt  = null;
                #endregion

                #region 把外键表加入DataSet
                DataTable dtMapAttr = myds.Tables["Sys_MapAttr"];
                MapExts   mes       = md.MapExts;
                foreach (DataRow dr in dtMapAttr.Rows)
                {
                    string lgType    = dr["LGType"].ToString();
                    string uiBindKey = dr["UIBindKey"].ToString();

                    if (DataType.IsNullOrEmpty(uiBindKey) == true)
                    {
                        continue; //为空就continue.
                    }
                    if (lgType.Equals("1") == true)
                    {
                        continue; //枚举值就continue;
                    }
                    string uiIsEnable = dr["UIIsEnable"].ToString();
                    if (uiIsEnable.Equals("0") == true && lgType.Equals("1") == true)
                    {
                        continue; //如果是外键,并且是不可以编辑的状态.
                    }
                    if (uiIsEnable.Equals("1") == true && lgType.Equals("0") == true)
                    {
                        continue; //如果是外部数据源,并且是不可以编辑的状态.
                    }
                    // 检查是否有下拉框自动填充。
                    string keyOfEn    = dr["KeyOfEn"].ToString();
                    string fk_mapData = dr["FK_MapData"].ToString();


                    #region 处理下拉框数据范围. for 小杨.
                    me = mes.GetEntityByKey(MapExtAttr.ExtType, MapExtXmlList.AutoFullDLL, MapExtAttr.AttrOfOper, keyOfEn) as MapExt;
                    if (me != null)
                    {
                        string fullSQL = me.Doc.Clone() as string;
                        fullSQL = fullSQL.Replace("~", ",");
                        fullSQL = BP.WF.Glo.DealExp(fullSQL, wk, null);
                        dt      = DBAccess.RunSQLReturnTable(fullSQL);
                        //重构新表
                        DataTable dt_FK_Dll = new DataTable();
                        dt_FK_Dll.TableName = keyOfEn;//可能存在隐患,如果多个字段,绑定同一个表,就存在这样的问题.
                        dt_FK_Dll.Columns.Add("No", typeof(string));
                        dt_FK_Dll.Columns.Add("Name", typeof(string));
                        foreach (DataRow dllRow in dt.Rows)
                        {
                            DataRow drDll = dt_FK_Dll.NewRow();
                            drDll["No"]   = dllRow["No"];
                            drDll["Name"] = dllRow["Name"];
                            dt_FK_Dll.Rows.Add(drDll);
                        }
                        myds.Tables.Add(dt_FK_Dll);
                        continue;
                    }
                    #endregion 处理下拉框数据范围.

                    // 判断是否存在.
                    if (myds.Tables.Contains(uiBindKey) == true)
                    {
                        continue;
                    }

                    if (BP.Sys.PubClass.GetDataTableByUIBineKey(uiBindKey) != null)
                    {
                        myds.Tables.Add(BP.Sys.PubClass.GetDataTableByUIBineKey(uiBindKey));
                    }
                }
                #endregion End把外键表加入DataSet

                #region 处理流程-消息提示.
                DataTable dtAlert = new DataTable();
                dtAlert.TableName = "AlertMsg";

                dtAlert.Columns.Add("Title", typeof(string));
                dtAlert.Columns.Add("Msg", typeof(string));
                dtAlert.Columns.Add("URL", typeof(string));

                //  string msg = "";
                switch (gwf.WFState)
                {
                case WFState.AskForReplay:     // 返回加签的信息.
                    string mysql = "SELECT * FROM ND" + int.Parse(fk_flow) + "Track WHERE WorkID=" + workID + " AND " + TrackAttr.ActionType + "=" + (int)ActionType.ForwardAskfor;

                    DataTable mydt = BP.DA.DBAccess.RunSQLReturnTable(mysql);
                    foreach (DataRow dr in mydt.Rows)
                    {
                        string msgAskFor  = dr[TrackAttr.Msg].ToString();
                        string worker     = dr[TrackAttr.EmpFrom].ToString();
                        string workerName = dr[TrackAttr.EmpFromT].ToString();
                        string rdt        = dr[TrackAttr.RDT].ToString();

                        DataRow drMsg = dtAlert.NewRow();
                        drMsg["Title"] = worker + "," + workerName + "回复信息:";
                        drMsg["Msg"]   = DataType.ParseText2Html(msgAskFor) + "<br>" + rdt;
                        dtAlert.Rows.Add(drMsg);
                    }
                    break;

                case WFState.Askfor:     //加签.

                    sql = "SELECT * FROM ND" + int.Parse(fk_flow) + "Track WHERE WorkID=" + workID + " AND " + TrackAttr.ActionType + "=" + (int)ActionType.AskforHelp;
                    dt  = BP.DA.DBAccess.RunSQLReturnTable(sql);
                    foreach (DataRow dr in dt.Rows)
                    {
                        string msgAskFor  = dr[TrackAttr.Msg].ToString();
                        string worker     = dr[TrackAttr.EmpFrom].ToString();
                        string workerName = dr[TrackAttr.EmpFromT].ToString();
                        string rdt        = dr[TrackAttr.RDT].ToString();

                        DataRow drMsg = dtAlert.NewRow();
                        drMsg["Title"] = worker + "," + workerName + "请求加签:";
                        drMsg["Msg"]   = DataType.ParseText2Html(msgAskFor) + "<br>" + rdt + "<a href='./WorkOpt/AskForRe.htm?FK_Flow=" + fk_flow + "&FK_Node=" + fk_node + "&WorkID=" + workID + "&FID=" + fid + "' >回复加签意见</a> --";
                        dtAlert.Rows.Add(drMsg);

                        //提示信息.
                        // this.FlowMsg.AlertMsg_Info(worker + "," + workerName + "请求加签:",
                        //   DataType.ParseText2Html(msgAskFor) + "<br>" + rdt + " --<a href='./WorkOpt/AskForRe.aspx?FK_Flow=" + this.FK_Flow + "&FK_Node=" + this.FK_Node + "&WorkID=" + this.WorkID + "&FID=" + this.FID + "' >回复加签意见</a> --");
                    }
                    // isAskFor = true;
                    break;

                case WFState.ReturnSta:
                    /* 如果工作节点退回了*/
                    ReturnWorks rws = new ReturnWorks();
                    rws.Retrieve(ReturnWorkAttr.ReturnToNode, fk_node,
                                 ReturnWorkAttr.WorkID, workID,
                                 ReturnWorkAttr.RDT);

                    if (rws.Count != 0)
                    {
                        //string msgInfo = "";
                        //foreach (BP.WF.ReturnWork rw in rws)
                        //{
                        //    DataRow drMsg = dtAlert.NewRow();
                        //    //drMsg["Title"] = "来自节点:" + rw.ReturnNodeName + " 退回人:" + rw.ReturnerName + "  " + rw.RDT + "&nbsp;<a href='/DataUser/ReturnLog/" + fk_flow + "/" + rw.MyPK + ".htm' target=_blank>工作日志</a>";
                        //    drMsg["Title"] = "来自节点:" + rw.ReturnNodeName + " 退回人:" + rw.ReturnerName + "  " + rw.RDT;
                        //    drMsg["Msg"] = rw.BeiZhuHtml;
                        //    dtAlert.Rows.Add(drMsg);
                        //}

                        string msgInfo = "";
                        foreach (BP.WF.ReturnWork rw in rws)
                        {
                            //drMsg["Title"] = "来自节点:" + rw.ReturnNodeName + " 退回人:" + rw.ReturnerName + "  " + rw.RDT + "&nbsp;<a href='/DataUser/ReturnLog/" + fk_flow + "/" + rw.MyPK + ".htm' target=_blank>工作日志</a>";
                            msgInfo += "\t\n来自节点:" + rw.ReturnNodeName + " 退回人:" + rw.ReturnerName + "  " + rw.RDT;
                            msgInfo += rw.BeiZhuHtml;
                        }

                        string str = nd.ReturnAlert;
                        if (str != "")
                        {
                            str = str.Replace("~", "'");
                            str = str.Replace("@PWorkID", workID.ToString());
                            str = str.Replace("@PNodeID", nd.NodeID.ToString());
                            str = str.Replace("@FK_Node", nd.NodeID.ToString());

                            str = str.Replace("@PFlowNo", fk_flow);
                            str = str.Replace("@FK_Flow", fk_flow);
                            str = str.Replace("@PWorkID", workID.ToString());

                            str = str.Replace("@WorkID", workID.ToString());
                            str = str.Replace("@OID", workID.ToString());

                            DataRow drMsg = dtAlert.NewRow();
                            drMsg["Title"] = "退回信息";
                            drMsg["Msg"]   = msgInfo + "\t\n" + str;
                            dtAlert.Rows.Add(drMsg);
                        }
                        else
                        {
                            DataRow drMsg = dtAlert.NewRow();
                            drMsg["Title"] = "退回信息";
                            drMsg["Msg"]   = msgInfo + "\t\n" + str;
                            dtAlert.Rows.Add(drMsg);
                        }
                    }
                    break;

                case WFState.Shift:
                    /* 判断移交过来的。 */
                    ShiftWorks        fws = new ShiftWorks();
                    BP.En.QueryObject qo  = new QueryObject(fws);
                    qo.AddWhere(ShiftWorkAttr.WorkID, workID);
                    qo.addAnd();
                    qo.AddWhere(ShiftWorkAttr.FK_Node, fk_node);
                    qo.addOrderBy(ShiftWorkAttr.RDT);
                    qo.DoQuery();
                    if (fws.Count >= 1)
                    {
                        DataRow drMsg = dtAlert.NewRow();
                        drMsg["Title"] = "移交历史信息";
                        msg            = "";
                        foreach (ShiftWork fw in fws)
                        {
                            string temp = "@移交人[" + fw.FK_Emp + "," + fw.FK_EmpName + "]。@接受人:" + fw.ToEmp + "," + fw.ToEmpName + "。<br>移交原因:-------------" + fw.NoteHtml;
                            if (fw.FK_Emp == WebUser.No)
                            {
                                temp = "<b>" + temp + "</b>";
                            }

                            temp = temp.Replace("@", "<br>@");
                            msg += temp + "<hr/>";
                        }
                        drMsg["Msg"] = msg;
                        dtAlert.Rows.Add(drMsg);
                    }
                    break;

                default:
                    break;
                }
                #endregion

                #region 增加流程节点表单绑定信息.
                if (nd.HisFormType == NodeFormType.RefOneFrmTree)
                {
                    /* 独立流程节点表单. */

                    nd.WorkID = workID; //为获取表单ID ( NodeFrmID )提供参数.

                    FrmNode fn = new FrmNode();
                    fn.MyPK = nd.NodeFrmID + "_" + nd.NodeID + "_" + nd.FK_Flow;
                    fn.Retrieve();
                    myds.Tables.Add(fn.ToDataTableField("FrmNode"));
                }
                #endregion 增加流程节点表单绑定信息.


                myds.Tables.Add(dtAlert);
                return(myds);
            }
            catch (Exception ex)
            {
                Log.DebugWriteError(ex.StackTrace);
                throw new Exception(ex.Message);
            }
        }
Esempio n. 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = "从表设计";

            MapData.IsEditDtlModel = true;
            MapData md  = new MapData(this.FK_MapData);
            MapDtl  dtl = new MapDtl(this.FK_MapDtl);

            if (dtl.IsView == false)
            {
                return;
            }

            MapAttrs attrs      = new MapAttrs(this.MyPK);
            MapAttrs attrs2     = new MapAttrs();
            MapExts  mes        = new MapExts(this.MyPK);
            string   LinkFields = ",";

            if (mes.Count != 0)
            {
                foreach (MapExt me in mes)
                {
                    switch (me.ExtType)
                    {
                    case MapExtXmlList.Link:
                        LinkFields += me.AttrOfOper + ",";
                        break;

                    default:
                        break;
                    }
                }

                this.Page.RegisterClientScriptBlock("s8",
                                                    "<script language='JavaScript' src='../Scripts/jquery-1.4.1.min.js' ></script>");

                this.Page.RegisterClientScriptBlock("b8",
                                                    "<script language='JavaScript' src='../CCForm/MapExt.js' ></script>");

                this.Page.RegisterClientScriptBlock("dCd",
                                                    "<script language='JavaScript' src='/DataUser/JSLibData/" + this.FK_MapDtl + ".js' ></script>");

                this.Pub1.Add("<div id='divinfo' style='width: 155px; position: absolute; color: Lime; display: none;cursor: pointer;align:left'></div>");
            }

            string t = DateTime.Now.ToString("MM-dd-hh:mm:ss");

            if (attrs.Count == 0)
            {
                dtl.IntMapAttrs();
            }


            this.Title = md.Name + " - 设计明细";
            this.Pub1.AddTable("class='Table' border='0' ID='Tab' cellspacing='0' cellpadding='0' ");
            //     this.Pub1.AddCaptionLeftTX("<a href='MapDef.aspx?MyPK=" + md.No + "' ><img src='../Img/Btn/Back.gif' border=0/>" + this.ToE("Back","返回") + ":" + md.Name + "</a> - <img src='../Img/Btn/Table.gif' border=0/>" + dtl.Name + " - <a href=\"javascript:AddF('" + this.MyPK + "');\" ><img src='../Img/Btn/New.gif' border=0/>" + "新建字段" + "</a> ");
            this.Pub1.Add(dtl.MTR);

            #region 输出标题.
            this.Pub1.AddTR();
            if (dtl.IsShowIdx)
            {
                this.Pub1.AddTDTitle("");
            }

            foreach (MapAttr attr in attrs)
            {
                if (attr.UIVisible == false)
                {
                    continue;
                }

                this.Pub1.Add("<TH style='width:" + attr.UIWidthInt + "px'>");
                this.Pub1.Add("<a href=\"javascript:Up('" + this.MyPK + "','" + attr.MyPK + "','" + t + "');\" ><img src='../Img/Btn/Left.gif' class=Arrow alt='向左移动' border=0/></a>");
                if (attr.HisEditType == EditType.UnDel || attr.HisEditType == EditType.Edit)
                {
                    switch (attr.LGType)
                    {
                    case FieldTypeS.Normal:
                        this.Pub1.Add("<a href=\"javascript:Edit('" + this.MyPK + "','" + attr.MyPK + "','" + attr.MyDataType + "');\"  alt='" + attr.KeyOfEn + "'>" + attr.Name + "</a>");
                        break;

                    case FieldTypeS.Enum:
                        this.Pub1.Add("<a href=\"javascript:EditEnum('" + this.MyPK + "','" + attr.MyPK + "');\" alt='" + attr.KeyOfEn + "' >" + attr.Name + "</a>");
                        break;

                    case FieldTypeS.FK:
                        this.Pub1.Add("<a href=\"javascript:EditTable('" + this.MyPK + "','" + attr.MyPK + "','" + attr.MyDataTypeS + "');\"  alt='" + attr.KeyOfEn + "'>" + attr.Name + "</a>");
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    this.Pub1.Add(attr.Name);
                }
                //  this.Pub1.Add("[<a href=\"javascript:Insert('" + this.MyPK + "','" + attr.Idx + "');\" ><img src='../Img/Btn/Insert.gif' border=0/>插入</a>]");
                this.Pub1.Add("<a href=\"javascript:Down('" + this.MyPK + "','" + attr.MyPK + "','" + t + "');\" ><img src='../Img/Btn/Right.gif' class=Arrow alt='向右移动' border=0/></a>");
                this.Pub1.Add("</TH>");
            }

            if (dtl.IsEnableAthM)
            {
                this.Pub1.AddTDTitle("<a href=\"javascript:Attachment('" + dtl.No + "');\"><img src='./../Img/set.gif' border=0 width='16px' /></a>");
            }

            if (dtl.IsEnableM2M)
            {
                this.Pub1.AddTDTitle("<a href=\"javascript:MapM2M('" + dtl.No + "');\"><img src='./../Img/set.gif' border=0 width='16px' /></a>");
            }

            if (dtl.IsEnableM2MM)
            {
                this.Pub1.AddTDTitle("<a href=\"javascript:window.showModalDialog('MapM2MM.aspx?NoOfObj=M2MM&FK_MapData=" + this.FK_MapDtl + "','m2m','dialogHeight: 500px; dialogWidth: 600px;center: yes; help: no')\"><img src='./../Img/set.gif' border=0 width='16px' /></a>");
            }

            if (dtl.IsEnableLink)
            {
                this.Pub1.AddTDTitle(dtl.LinkLabel);
            }

            //Pub1.AddTDTitle("&nbsp;");

            this.Pub1.AddTREnd();
            #endregion 输出标题.

            #region 输出行.
            for (int i = 1; i <= dtl.RowsOfList; i++)
            {
                this.Pub1.AddTR();
                if (dtl.IsShowIdx)
                {
                    this.Pub1.AddTDIdx(i);
                }
                foreach (MapAttr attr in attrs)
                {
                    if (attr.UIVisible == false)
                    {
                        continue;
                    }

                    #region 是否输出超连接.
                    if (attr.UIIsEnable == false && LinkFields.Contains("," + attr.KeyOfEn + ","))
                    {
                        MapExt meLink = mes.GetEntityByKey(MapExtAttr.ExtType, MapExtXmlList.Link) as MapExt;
                        string url    = meLink.Tag;
                        if (url.Contains("?") == false)
                        {
                            url = url + "?a3=2";
                        }
                        url = url + "&WebUserNo=" + WebUser.No + "&SID=" + WebUser.SID + "&EnName=" + this.FK_MapDtl;
                        if (url.Contains("@AppPath"))
                        {
                            url = url.Replace("@AppPath", "http://" + this.Request.Url.Host + this.Request.ApplicationPath);
                        }
                        if (url.Contains("@"))
                        {
                            if (attrs2.Count == 0)
                            {
                                attrs2 = new MapAttrs(this.FK_MapDtl);
                            }
                            foreach (MapAttr item in attrs2)
                            {
                                url = url.Replace("@" + item.KeyOfEn, item.DefVal);
                                if (url.Contains("@") == false)
                                {
                                    break;
                                }
                            }
                        }
                        this.Pub1.AddTD("<a href='" + url + "' target='" + meLink.Tag1 + "' >" + attr.DefVal + "</a>");
                        continue;
                    }
                    #endregion 是否输出超连接.

                    #region 输出字段.
                    switch (attr.LGType)
                    {
                    case FieldTypeS.Normal:
                        if (attr.MyDataType == BP.DA.DataType.AppBoolean)
                        {
                            CheckBox cb = new CheckBox();
                            cb.Checked = attr.DefValOfBool;
                            cb.Enabled = attr.UIIsEnable;
                            cb.Text    = attr.Name;
                            this.Pub1.AddTD(cb);
                            break;
                        }
                        TextBox tb = new TextBox();
                        tb.ID       = "TB_" + attr.KeyOfEn + "_" + i;
                        tb.Text     = attr.DefVal;
                        tb.ReadOnly = !attr.UIIsEnable;
                        this.Pub1.AddTD(tb);
                        switch (attr.MyDataType)
                        {
                        case BP.DA.DataType.AppString:
                            tb.Attributes["style"] = "width:" + attr.UIWidth + "px;border: none;";
                            if (attr.UIHeight > 25)
                            {
                                tb.TextMode             = TextBoxMode.MultiLine;
                                tb.Attributes["Height"] = attr.UIHeight + "px";
                                tb.Rows = attr.UIHeightInt / 25;
                            }
                            break;

                        case BP.DA.DataType.AppDateTime:
                            tb.Attributes["style"] = "width:" + attr.UIWidth + "px;border: none;";
                            if (attr.UIIsEnable)
                            {
                                tb.Attributes["onfocus"] = "WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'});";
                                //tb.Attributes["class"] = "TBcalendar";
                            }
                            break;

                        case BP.DA.DataType.AppDate:
                            tb.Attributes["style"] = "width:" + attr.UIWidth + "px;border: none;";
                            if (attr.UIIsEnable)
                            {
                                tb.Attributes["onfocus"] = "WdatePicker();";
                                //  tb.Attributes["class"] = "TBcalendar";
                            }
                            break;

                        default:
                            tb.Attributes["style"] = "width:" + attr.UIWidth + "px;border: none;";
                            if (tb.ReadOnly == false)
                            {
                                // OnKeyPress="javascript:return VirtyNum(this);"
                                //tb.Attributes["OnKeyDown"] = "javascript:return VirtyNum(this);";

                                if (attr.MyDataType == DataType.AppInt)
                                {
                                    tb.Attributes["OnKeyDown"] = "javascript:return VirtyInt(this);";
                                }
                                else
                                {
                                    tb.Attributes["OnKeyDown"] = "javascript:return VirtyNum(this);";
                                }

                                tb.Attributes["onkeyup"] += "javascript:C" + i + "();C" + attr.KeyOfEn + "();";
                                tb.Attributes["class"]    = "TBNum";
                            }
                            else
                            {
                                // tb.Attributes["onpropertychange"] += "C" + attr.KeyOfEn + "();";
                                tb.Attributes["class"] = "TBNumReadonly";
                            }
                            break;
                        }
                        break;

                    case FieldTypeS.Enum:
                        DDL ddl = new DDL();
                        ddl.ID = "DDL_" + attr.KeyOfEn + "_" + i;
                        try
                        {
                            ddl.BindSysEnum(attr.KeyOfEn);
                            ddl.SetSelectItem(attr.DefVal);
                        }
                        catch (Exception ex)
                        {
                            BP.Sys.PubClass.Alert(ex.Message);
                        }
                        ddl.Enabled = attr.UIIsEnable;
                        this.Pub1.AddTDCenter(ddl);
                        break;

                    case FieldTypeS.FK:
                        DDL ddl1 = new DDL();
                        ddl1.ID = "DDL_" + attr.KeyOfEn + "_" + i;
                        try
                        {
                            EntitiesNoName ens = attr.HisEntitiesNoName;
                            ens.RetrieveAll();
                            ddl1.BindEntities(ens);
                            if (ddl1.SetSelectItem(attr.DefVal) == false)
                            {
                                ddl1.Items.Insert(0, new ListItem("请选择", attr.DefVal));
                                ddl1.SelectedIndex = 0;
                            }
                        }
                        catch
                        {
                        }
                        ddl1.Enabled = attr.UIIsEnable;
                        this.Pub1.AddTDCenter(ddl1);
                        break;

                    default:
                        break;
                    }
                    #endregion s输出字段.
                }

                #region 输出附件,m2m
                if (dtl.IsEnableAthM)
                {
                    this.Pub1.AddTD("<a href=\"javascript:EnableAthM('" + this.FK_MapDtl + "');\" ><img src='../Img/AttachmentM.png' border=0 width='16px' /></a>");
                }

                if (dtl.IsEnableM2M)
                {
                    this.Pub1.AddTD("<a href=\"javascript:window.showModalDialog('../CCForm/M2M.aspx?NoOfObj=M2M&IsTest=1&OID=0&FK_MapData=" + this.FK_MapDtl + "','m2m','dialogHeight: 500px; dialogWidth: 600px;center: yes; help: no')\"><img src='./../Img/M2M.png' border=0 width='16px' /></a>");
                }

                if (dtl.IsEnableM2MM)
                {
                    this.Pub1.AddTD("<a href=\"javascript:window.showModalDialog('../CCForm/M2MM.aspx?NoOfObj=M2MM&IsTest=1&OID=0&FK_MapData=" + this.FK_MapDtl + "','m2m','dialogHeight: 500px; dialogWidth: 600px;center: yes; help: no')\"><img src='./../Img/M2MM.png' border=0 width='16px' /></a>");
                }

                if (dtl.IsEnableLink)
                {
                    this.Pub1.AddTD("<a href='" + dtl.LinkUrl + "' target='" + dtl.LinkTarget + "' >" + dtl.LinkLabel + "</a>");
                }
                #endregion 输出附件,m2m

                //Pub1.AddTD("&nbsp;");
                this.Pub1.AddTREnd();
            }
            #endregion 输出行.

            #region 合计.
            if (dtl.IsShowSum)
            {
                this.Pub1.AddTRSum();
                if (dtl.IsShowIdx)
                {
                    this.Pub1.AddTD("合计");
                }

                foreach (MapAttr attr in attrs)
                {
                    if (attr.UIVisible == false)
                    {
                        continue;
                    }
                    if (attr.IsNum && attr.LGType == FieldTypeS.Normal)
                    {
                        TB tb = new TB();
                        tb.ID                  = "TB_" + attr.KeyOfEn;
                        tb.Text                = attr.DefVal;
                        tb.ShowType            = attr.HisTBType;
                        tb.ReadOnly            = true;
                        tb.Font.Bold           = true;
                        tb.BackColor           = System.Drawing.Color.FromName("#FFFFFF");
                        tb.Attributes["class"] = "TBNumReadonly";
                        this.Pub1.AddTD(tb);
                    }
                    else
                    {
                        this.Pub1.AddTD();
                    }
                }
                if (dtl.IsEnableAthM)
                {
                    this.Pub1.AddTD();
                }

                if (dtl.IsEnableM2M)
                {
                    this.Pub1.AddTD();
                }

                if (dtl.IsEnableM2MM)
                {
                    this.Pub1.AddTD();
                }

                if (dtl.IsEnableLink)
                {
                    this.Pub1.AddTD();
                }

                //    Pub1.AddTD("&nbsp;");
                this.Pub1.AddTREnd();
            }
            this.Pub1.AddTableEnd();
            #endregion 合计.

            #region 处理设计时自动填充从表.
            if (this.Key != null)
            {
                MapExt   me   = new MapExt(this.FK_MapExt);
                string[] strs = me.Tag1.Split('$');
                foreach (string str in strs)
                {
                    if (str.Contains(this.FK_MapDtl) == false)
                    {
                        continue;
                    }

                    string[] ss = str.Split(':');

                    string sql = ss[1];
                    sql = sql.Replace("@Key", this.Key);
                    sql = sql.Replace("@key", this.Key);
                    sql = sql.Replace("@val", this.Key);
                    sql = sql.Replace("@Val", this.Key);

                    DataTable dt  = DBAccess.RunSQLReturnTable(sql);
                    int       idx = 0;
                    foreach (DataRow dr in dt.Rows)
                    {
                        idx++;
                        foreach (DataColumn dc in dt.Columns)
                        {
                            string val = dr[dc.ColumnName].ToString();
                            try
                            {
                                this.Pub1.GetTextBoxByID("TB_" + dc.ColumnName + "_" + idx).Text = val;
                            }
                            catch
                            {
                            }

                            try
                            {
                                this.Pub1.GetDDLByID("DDL_" + dc.ColumnName + "_" + idx).SetSelectItem(val);
                            }
                            catch
                            {
                            }
                        }
                    }
                }
            }
            #endregion 处理设计时自动填充从表.

            #region 处理拓展属性.
            for (int i = 1; i <= dtl.RowsOfList; i++)
            {
                foreach (MapExt me in mes)
                {
                    switch (me.ExtType)
                    {
                    case MapExtXmlList.DDLFullCtrl:     // 自动填充.
                        DDL ddlOper = this.Pub1.GetDDLByID("DDL_" + me.AttrOfOper);
                        if (ddlOper == null)
                        {
                            continue;
                        }
                        ddlOper.Attributes["onchange"] = "DDLFullCtrl(this.value,\'" + ddlOper.ClientID + "\', \'" + me.MyPK + "\')";
                        break;

                    case MapExtXmlList.ActiveDDL:
                        DDL ddlPerant = this.Pub1.GetDDLByID("DDL_" + me.AttrOfOper + "_" + i);
                        if (ddlPerant == null)
                        {
                            me.Delete();
                            continue;
                        }

                        DDL ddlChild = this.Pub1.GetDDLByID("DDL_" + me.AttrsOfActive + "_" + i);
                        if (ddlChild == null)
                        {
                            me.Delete();
                            continue;
                        }

                        ddlPerant.Attributes["onchange"] = "DDLAnsc(this.value,\'" + ddlChild.ClientID + "\', \'" + me.MyPK + "\')";
                        if (ddlPerant.Items.Count == 0)
                        {
                            continue;
                        }

                        string val = ddlPerant.SelectedItemStringVal;

                        string valC1 = ddlChild.SelectedItemStringVal;


                        DataTable dt = DBAccess.RunSQLReturnTable(me.Doc.Replace("@Key", val));

                        ddlChild.Items.Clear();
                        foreach (DataRow dr in dt.Rows)
                        {
                            ddlChild.Items.Add(new ListItem(dr[1].ToString(), dr[0].ToString()));
                        }
                        ddlChild.SetSelectItem(valC1);
                        break;

                    case MapExtXmlList.AutoFullDLL:     //自动填充下拉框的范围.
                        DDL ddlFull = this.Pub1.GetDDLByID("DDL_" + me.AttrOfOper + "_" + i);
                        if (ddlFull == null)
                        {
                            me.Delete();
                            continue;
                        }

                        string valOld = ddlFull.SelectedItemStringVal;
                        ddlFull.Items.Clear();
                        string fullSQL = me.Doc.Replace("@WebUser.No", WebUser.No);
                        fullSQL = fullSQL.Replace("@WebUser.FK_Dept", WebUser.FK_Dept);
                        fullSQL = fullSQL.Replace("@WebUser.Name", WebUser.Name);

                        if (fullSQL.Contains("@"))
                        {
                            //Attrs attrsFull = mydtl.EnMap.Attrs;
                            //foreach (Attr attr in attrsFull)
                            //{
                            //    if (fullSQL.Contains("@") == false)
                            //        break;
                            //    fullSQL = fullSQL.Replace("@" + attr.Key, mydtl.GetValStrByKey(attr.Key));
                            //}
                        }
                        ddlFull.Bind(DBAccess.RunSQLReturnTable(fullSQL), "No", "Name");
                        ddlFull.SetSelectItem(valOld);
                        break;

                    case MapExtXmlList.TBFullCtrl:     // 自动填充.
                        TextBox tbAuto = this.Pub1.GetTextBoxByID("TB_" + me.AttrOfOper + "_" + i);
                        if (tbAuto == null)
                        {
                            me.Delete();
                            continue;
                        }
                        tbAuto.Attributes["onkeyup"]      = "DoAnscToFillDiv(this,this.value,\'" + tbAuto.ClientID + "\', \'" + me.MyPK + "\');";
                        tbAuto.Attributes["AUTOCOMPLETE"] = "OFF";
                        if (me.Tag != "")
                        {
                            /* 处理下拉框的选择范围的问题 */
                            string[] strs = me.Tag.Split('$');
                            foreach (string str in strs)
                            {
                                string[] myCtl = str.Split(':');
                                string   ctlID = myCtl[0];
                                DDL      ddlC  = this.Pub1.GetDDLByID("DDL_" + ctlID + "_" + i);
                                if (ddlC == null)
                                {
                                    continue;
                                }

                                string sql = myCtl[1].Replace("~", "'");
                                sql = sql.Replace("@WebUser.No", WebUser.No);
                                sql = sql.Replace("@WebUser.Name", WebUser.Name);
                                sql = sql.Replace("@WebUser.FK_Dept", WebUser.FK_Dept);
                                sql = sql.Replace("@Key", tbAuto.Text.Trim());
                                dt  = DBAccess.RunSQLReturnTable(sql);
                                string valC = ddlC.SelectedItemStringVal;
                                ddlC.Items.Clear();
                                foreach (DataRow dr in dt.Rows)
                                {
                                    ddlC.Items.Add(new ListItem(dr[1].ToString(), dr[0].ToString()));
                                }
                                ddlC.SetSelectItem(valC);
                            }
                        }
                        // tbAuto.Attributes["onkeyup"] = "DoAnscToFillDiv(this,this.value);";
                        // tbAuto.Attributes["onkeyup"] = "DoAnscToFillDiv(this,this.value,\'" + tbAuto.ClientID + "\', \'" + me.MyPK + "\');";
                        break;

                    case MapExtXmlList.InputCheck:
                        TextBox tbCheck = this.Pub1.GetTextBoxByID("TB_" + me.AttrOfOper + "_" + i);
                        if (tbCheck != null)
                        {
                            tbCheck.Attributes[me.Tag2] += " rowPK=" + i + ";" + me.Tag1 + "(this);";
                        }
                        else
                        {
                            me.Delete();
                        }
                        break;

                    case MapExtXmlList.PopVal:     //弹出窗.
                        TextBox tb = this.Pub1.GetTextBoxByID("TB_" + me.AttrOfOper + "_" + i);
                        if (tb == null)
                        {
                            continue;
                        }
                        //tb.Attributes["ondblclick"] = "return ReturnValCCFormPopVal(this,'" + me.MyPK + "','33');";
                        tb.Attributes["ondblclick"] = "ReturnValCCFormPopVal(this,'" + me.MyPK + "','33');";
                        //    throw new Exception("ssssrrrss");
                        break;

                    default:
                        break;
                    }
                }
            }
            #endregion 处理拓展属性.

            #region 输出自动计算公式
            this.Pub1.Add("\n <script language='JavaScript'>");
            MapExts exts = new MapExts(dtl.No);
            foreach (MapExt ext in exts)
            {
                if (ext.ExtType != MapExtXmlList.AutoFull)
                {
                    continue;
                }

                for (int i = 1; i <= dtl.RowsOfList; i++)
                {
                    string top    = "\n function C" + i + "() { \n ";
                    string script = "";
                    foreach (MapAttr attr in attrs)
                    {
                        if (attr.UIVisible == false)
                        {
                            continue;
                        }
                        if (attr.IsNum == false)
                        {
                            continue;
                        }

                        if (attr.LGType != FieldTypeS.Normal)
                        {
                            continue;
                        }

                        if (ext.Tag == "1" && ext.Doc != "")
                        {
                            script += this.GenerAutoFull(i.ToString(), attrs, ext);
                        }
                    }
                    string end = " \n  } ";
                    this.Pub1.Add(top + script + end);
                }
            }
            this.Pub1.Add("\n</script>");

            // 输出合计算计公式
            foreach (MapAttr attr in attrs)
            {
                if (attr.UIVisible == false)
                {
                    continue;
                }

                if (attr.LGType != FieldTypeS.Normal)
                {
                    continue;
                }

                if (attr.IsNum == false)
                {
                    continue;
                }

                if (attr.MyDataType == DataType.AppBoolean)
                {
                    continue;
                }

                string top = "\n<script language='JavaScript'> function C" + attr.KeyOfEn + "() { \n ";
                string end = "\n } </script>";
                this.Pub1.Add(top + this.GenerSum(attr, dtl) + " ; \t\n" + end);
            }
            #endregion 输出自动计算公式
        }
Esempio n. 3
0
        /// <summary>
        /// 获取从表数据,用于显示dtl.htm
        /// </summary>
        /// <param name="frmID">表单ID</param>
        /// <param name="pkval">主键</param>
        /// <param name="atParas">参数</param>
        /// <param name="specDtlFrmID">指定明细表的参数,如果为空就标识主表数据,否则就是从表数据.</param>
        /// <returns>数据</returns>
        public static DataSet GenerDBForCCFormDtl(string frmID, MapDtl dtl, int pkval, string atParas)
        {
            //数据容器,就是要返回的对象.
            DataSet myds = new DataSet();

            //映射实体.
            MapData md = new MapData(frmID);

            //实体.
            GEEntity wk = new GEEntity(frmID);

            wk.OID = pkval;
            if (wk.RetrieveFromDBSources() == 0)
            {
                wk.Insert();
            }

            //把参数放入到 En 的 Row 里面。
            if (DataType.IsNullOrEmpty(atParas) == false)
            {
                AtPara ap = new AtPara(atParas);
                foreach (string key in ap.HisHT.Keys)
                {
                    try
                    {
                        if (wk.Row.ContainsKey(key) == true) //有就该变.
                        {
                            wk.Row[key] = ap.GetValStrByKey(key);
                        }
                        else
                        {
                            wk.Row.Add(key, ap.GetValStrByKey(key)); //增加他.
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(key);
                    }
                }
            }

            #region 加载从表表单模版信息.

            DataTable Sys_MapDtl = dtl.ToDataTableField("Sys_MapDtl");
            myds.Tables.Add(Sys_MapDtl);

            //明细表的表单描述
            DataTable Sys_MapAttr = dtl.MapAttrs.ToDataTableField("Sys_MapAttr");
            myds.Tables.Add(Sys_MapAttr);

            //明细表的配置信息.

            DataTable Sys_MapExt = dtl.MapExts.ToDataTableField("Sys_MapExt");
            myds.Tables.Add(Sys_MapExt);

            #region 把从表的- 外键表/枚举 加入 DataSet.
            MapExts mes = dtl.MapExts;
            MapExt  me  = null;

            foreach (DataRow dr in Sys_MapAttr.Rows)
            {
                string lgType = dr["LGType"].ToString();
                //不是枚举/外键字段
                if (lgType.Equals("0"))
                {
                    continue;
                }

                string uiBindKey = dr["UIBindKey"].ToString();
                var    mypk      = dr["MyPK"].ToString();

                #region 枚举字段
                if (lgType.Equals("1"))
                {
                    // 如果是枚举值, 判断是否存在.
                    if (myds.Tables.Contains(uiBindKey) == true)
                    {
                        continue;
                    }

                    string    mysql  = "SELECT IntKey AS No, Lab as Name FROM Sys_Enum WHERE EnumKey='" + uiBindKey + "' ORDER BY IntKey ";
                    DataTable dtEnum = DBAccess.RunSQLReturnTable(mysql);
                    dtEnum.TableName = uiBindKey;

                    dtEnum.Columns[0].ColumnName = "No";
                    dtEnum.Columns[1].ColumnName = "Name";

                    myds.Tables.Add(dtEnum);
                    continue;
                }
                #endregion

                #region 外键字段
                string UIIsEnable = dr["UIIsEnable"].ToString();
                if (UIIsEnable.Equals("0")) //字段未启用
                {
                    continue;
                }

                // 检查是否有下拉框自动填充。
                string keyOfEn = dr["KeyOfEn"].ToString();

                #region 处理下拉框数据范围. for 小杨.
                me = mes.GetEntityByKey(MapExtAttr.ExtType, MapExtXmlList.AutoFullDLL, MapExtAttr.AttrOfOper, keyOfEn) as MapExt;
                if (me != null) //有范围限制时
                {
                    string fullSQL = me.Doc.Clone() as string;
                    fullSQL = fullSQL.Replace("~", ",");
                    fullSQL = BP.WF.Glo.DealExp(fullSQL, wk, null);

                    DataTable dt = DBAccess.RunSQLReturnTable(fullSQL);

                    dt.TableName = uiBindKey;

                    dt.Columns[0].ColumnName = "No";
                    dt.Columns[1].ColumnName = "Name";

                    myds.Tables.Add(dt);
                    continue;
                }
                #endregion 处理下拉框数据范围.

                // 判断是否存在.
                if (myds.Tables.Contains(uiBindKey) == true)
                {
                    continue;
                }

                myds.Tables.Add(BP.Sys.PubClass.GetDataTableByUIBineKey(uiBindKey));
                #endregion 外键字段
            }
            #endregion 把从表的- 外键表/枚举 加入 DataSet.


            #endregion 加载从表表单模版信息.

            #region 把主表数据放入.
            if (BP.Sys.SystemConfig.IsBSsystem == true)
            {
                // 处理传递过来的参数。
                foreach (string k in System.Web.HttpContext.Current.Request.QueryString.AllKeys)
                {
                    wk.SetValByKey(k, System.Web.HttpContext.Current.Request.QueryString[k]);
                }
            }

            //重设默认值.
            wk.ResetDefaultVal();


            //增加主表数据.
            DataTable mainTable = wk.ToDataTableField(md.No);
            mainTable.TableName = "MainTable";
            myds.Tables.Add(mainTable);
            #endregion 把主表数据放入.

            #region  把从表的数据放入.
            GEDtls      dtls = new GEDtls(dtl.No);
            QueryObject qo   = null;
            try
            {
                qo = new QueryObject(dtls);
                switch (dtl.DtlOpenType)
                {
                case DtlOpenType.ForEmp:      // 按人员来控制.
                    qo.AddWhere(GEDtlAttr.RefPK, pkval);
                    qo.addAnd();
                    qo.AddWhere(GEDtlAttr.Rec, WebUser.No);
                    break;

                case DtlOpenType.ForWorkID:     // 按工作ID来控制
                    qo.AddWhere(GEDtlAttr.RefPK, pkval);
                    break;

                case DtlOpenType.ForFID:     // 按流程ID来控制.
                    qo.AddWhere(GEDtlAttr.FID, pkval);
                    break;
                }
            }
            catch (Exception ex)
            {
                dtls.GetNewEntity.CheckPhysicsTable();
                throw ex;
            }

            //条件过滤.
            if (dtl.FilterSQLExp != "")
            {
                string[] strs = dtl.FilterSQLExp.Split('=');
                qo.addAnd();
                qo.AddWhere(strs[0], strs[1]);
            }

            //增加排序.
            //    qo.addOrderByDesc( dtls.GetNewEntity.PKField );

            //从表
            DataTable dtDtl = qo.DoQueryToTable();

            //查询所有动态SQL查询类型的字典表记录
            SFTable   sftable   = null;
            DataTable dtsftable = null;
            DataRow[] drs       = null;

            SFTables sftables = new SFTables();
            sftables.Retrieve(SFTableAttr.SrcType, (int)SrcType.SQL);

            // 为明细表设置默认值.
            MapAttrs dtlAttrs = new MapAttrs(dtl.No);
            foreach (MapAttr attr in dtlAttrs)
            {
                #region 修改区分大小写.
                if (BP.DA.DBType.Oracle == SystemConfig.AppCenterDBType)
                {
                    foreach (DataColumn dr in dtDtl.Columns)
                    {
                        var a = attr.KeyOfEn;
                        var b = dr.ColumnName;
                        if (attr.KeyOfEn.ToUpper().Equals(dr.ColumnName))
                        {
                            dr.ColumnName = attr.KeyOfEn;
                            continue;
                        }

                        if (attr.LGType == FieldTypeS.Enum || attr.LGType == FieldTypeS.FK)
                        {
                            if (dr.ColumnName.Equals(attr.KeyOfEn.ToUpper() + "TEXT"))
                            {
                                dr.ColumnName = attr.KeyOfEn + "Text";
                            }
                        }
                    }
                    foreach (DataRow dr in dtDtl.Rows)
                    {
                        //本身是大写的不进行修改
                        if (DataType.IsNullOrEmpty(dr[attr.KeyOfEn] + ""))
                        {
                            dr[attr.KeyOfEn]           = dr[attr.KeyOfEn.ToUpper()];
                            dr[attr.KeyOfEn.ToUpper()] = null;
                        }
                    }
                }
                #endregion 修改区分大小写.

                //处理增加动态SQL查询类型的下拉框选中值Text值,added by liuxc,2017-9-22
                if (attr.LGType == FieldTypeS.FK && attr.UIIsEnable == false)
                {
                    sftable = sftables.GetEntityByKey(attr.UIBindKey) as SFTable;
                    if (sftable != null)
                    {
                        dtsftable = sftable.GenerHisDataTable;

                        //为Text赋值
                        foreach (DataRow dr in dtDtl.Rows)
                        {
                            drs = dtsftable.Select("No='" + dr[attr.KeyOfEn] + "'");
                            if (drs.Length == 0)
                            {
                                continue;
                            }

                            dr[attr.KeyOfEn + "Text"] = drs[0]["Name"];
                        }
                    }
                }

                //处理它的默认值.
                if (attr.DefValReal.Contains("@") == false)
                {
                    continue;
                }

                foreach (DataRow dr in dtDtl.Rows)
                {
                    dr[attr.KeyOfEn] = attr.DefVal;
                }
            }

            dtDtl.TableName = "DBDtl";          //修改明细表的名称.
            myds.Tables.Add(dtDtl);             //加入这个明细表, 如果没有数据,xml体现为空.
            #endregion 把从表的数据放入.


            //放入一个空白的实体,用与获取默认值.
            GEDtl dtlBlank = dtls.GetNewEntity as GEDtl;
            dtlBlank.ResetDefaultVal();

            myds.Tables.Add(dtlBlank.ToDataTableField("Blank"));

            return(myds);
        }
Esempio n. 4
0
        /// <summary>
        /// 仅获取表单数据
        /// </summary>
        /// <param name="frmID">表单ID</param>
        /// <param name="pkval">主键</param>
        /// <param name="atParas">参数</param>
        /// <param name="specDtlFrmID">指定明细表的参数,如果为空就标识主表数据,否则就是从表数据.</param>
        /// <returns>数据</returns>
        public static DataSet GenerDBForVSTOExcelFrmModel(string frmID, object pkval, string atParas, string specDtlFrmID = null)
        {
            //如果是一个实体类.
            if (frmID.Contains("BP."))
            {
                // 执行map同步.
                Entities ens = BP.En.ClassFactory.GetEns(frmID + "s");
                Entity   en  = ens.GetNewEntity;
                en.DTSMapToSys_MapData();

                return(GenerDBForVSTOExcelFrmModelOfEntity(frmID, pkval, atParas, specDtlFrmID = null));

                //上面这行代码的解释(2017-04-25):
                //若不加上这行,代码执行到“ MapData md = new MapData(frmID); ”会报错:
                //@没有找到记录[表单注册表  Sys_MapData, [ 主键=No 值=BP.LI.BZQX ]记录不存在,请与管理员联系, 或者确认输入错误.@在Entity(BP.Sys.MapData)查询期间出现错误@   在 BP.En.Entity.Retrieve() 位置 D:\ccflow\Components\BP.En30\En\Entity.cs:行号 1051
                //即使加上:
                //frmID = frmID.Substring(0, frmID.Length - 1);
                //也会出现该问题
                //2017-04-25 15:26:34:new MapData(frmID)应传入“BZQX”,但考虑到 GenerDBForVSTOExcelFrmModelOfEntity()运行稳定,暂不采用『统一执行下方代码』的方案。
            }

            //数据容器,就是要返回的对象.
            DataSet myds = new DataSet();

            //映射实体.
            MapData md = new MapData(frmID);

            //实体.
            GEEntity wk = new GEEntity(frmID);

            wk.OID = int.Parse(pkval.ToString());
            if (wk.RetrieveFromDBSources() == 0)
            {
                wk.Insert();
            }

            //加载事件.
            md.DoEvent(FrmEventList.FrmLoadBefore, wk, null);

            //把参数放入到 En 的 Row 里面。
            if (DataType.IsNullOrEmpty(atParas) == false)
            {
                AtPara ap = new AtPara(atParas);
                foreach (string key in ap.HisHT.Keys)
                {
                    if (wk.Row.ContainsKey(key) == true)                     //有就该变.
                    {
                        wk.Row[key] = ap.GetValStrByKey(key);
                    }
                    else
                    {
                        wk.Row.Add(key, ap.GetValStrByKey(key));                         //增加他.
                    }
                }
            }

            //属性.
            MapExt    me        = null;
            DataTable dtMapAttr = null;
            MapExts   mes       = null;



            #region 表单模版信息.(含主、从表的,以及从表的枚举/外键相关数据).
            //增加表单字段描述.
            string    sql = "SELECT * FROM Sys_MapData WHERE No='" + frmID + "' ";
            DataTable dt  = BP.DA.DBAccess.RunSQLReturnTable(sql);
            dt.TableName = "Sys_MapData";
            myds.Tables.Add(dt);

            //增加表单字段描述.
            sql          = "SELECT * FROM Sys_MapAttr WHERE FK_MapData='" + frmID + "' ";
            dt           = BP.DA.DBAccess.RunSQLReturnTable(sql);
            dt.TableName = "Sys_MapAttr";
            myds.Tables.Add(dt);

            //增加从表信息.
            sql          = "SELECT * FROM Sys_MapDtl WHERE FK_MapData='" + frmID + "' ";
            dt           = BP.DA.DBAccess.RunSQLReturnTable(sql);
            dt.TableName = "Sys_MapDtl";
            myds.Tables.Add(dt);


            //主表的配置信息.
            sql          = "SELECT * FROM Sys_MapExt WHERE FK_MapData='" + frmID + "'";
            dt           = BP.DA.DBAccess.RunSQLReturnTable(sql);
            dt.TableName = "Sys_MapExt";
            myds.Tables.Add(dt);

            #region 加载 从表表单模版信息.(含 从表的枚举/外键相关数据)
            foreach (MapDtl item in md.MapDtls)
            {
                #region 返回指定的明细表的数据.
                if (DataType.IsNullOrEmpty(specDtlFrmID) == true)
                {
                }
                else
                {
                    if (item.No != specDtlFrmID)
                    {
                        continue;
                    }
                }
                #endregion 返回指定的明细表的数据.

                //明细表的主表描述
                sql          = "SELECT * FROM Sys_MapDtl WHERE No='" + item.No + "'";
                dt           = BP.DA.DBAccess.RunSQLReturnTable(sql);
                dt.TableName = "Sys_MapDtl_For_" + (string.IsNullOrWhiteSpace(item.Alias) ? item.No : item.Alias);
                myds.Tables.Add(dt);

                //明细表的表单描述
                sql                 = "SELECT * FROM Sys_MapAttr WHERE FK_MapData='" + item.No + "'";
                dtMapAttr           = BP.DA.DBAccess.RunSQLReturnTable(sql);
                dtMapAttr.TableName = "Sys_MapAttr_For_" + (string.IsNullOrWhiteSpace(item.Alias) ? item.No : item.Alias);
                myds.Tables.Add(dtMapAttr);

                //明细表的配置信息.
                sql          = "SELECT * FROM Sys_MapExt WHERE FK_MapData='" + item.No + "'";
                dt           = BP.DA.DBAccess.RunSQLReturnTable(sql);
                dt.TableName = "Sys_MapExt_For_" + (string.IsNullOrWhiteSpace(item.Alias) ? item.No : item.Alias);
                myds.Tables.Add(dt);

                #region 从表的 外键表/枚举
                mes = new MapExts(item.No);
                foreach (DataRow dr in dtMapAttr.Rows)
                {
                    string lgType = dr["LGType"].ToString();
                    //不是枚举/外键字段
                    if (lgType.Equals("0"))
                    {
                        continue;
                    }

                    string uiBindKey = dr["UIBindKey"].ToString();
                    var    mypk      = dr["MyPK"].ToString();

                    #region 枚举字段
                    if (lgType.Equals("1"))
                    {
                        // 如果是枚举值, 判断是否存在.
                        if (myds.Tables.Contains(uiBindKey) == true)
                        {
                            continue;
                        }

                        string    mysql  = "SELECT IntKey AS No, Lab as Name FROM Sys_Enum WHERE EnumKey='" + uiBindKey + "' ORDER BY IntKey ";
                        DataTable dtEnum = DBAccess.RunSQLReturnTable(mysql);
                        dtEnum.TableName = uiBindKey;
                        myds.Tables.Add(dtEnum);
                        continue;
                    }
                    #endregion

                    string UIIsEnable = dr["UIIsEnable"].ToString();
                    if (UIIsEnable.Equals("0"))                     //字段未启用
                    {
                        continue;
                    }

                    #region 外键字段
                    // 检查是否有下拉框自动填充。
                    string keyOfEn = dr["KeyOfEn"].ToString();

                    #region 处理下拉框数据范围. for 小杨.
                    me = mes.GetEntityByKey(MapExtAttr.ExtType, MapExtXmlList.AutoFullDLL, MapExtAttr.AttrOfOper, keyOfEn) as MapExt;
                    if (me != null)                     //有范围限制时
                    {
                        string fullSQL = me.Doc.Clone() as string;
                        fullSQL = fullSQL.Replace("~", ",");
                        fullSQL = BP.WF.Glo.DealExp(fullSQL, wk, null);

                        dt = DBAccess.RunSQLReturnTable(fullSQL);

                        dt.TableName = mypk;
                        myds.Tables.Add(dt);
                        continue;
                    }
                    #endregion 处理下拉框数据范围.
                    else                     //无范围限制时
                    {
                        // 判断是否存在.
                        if (myds.Tables.Contains(uiBindKey) == true)
                        {
                            continue;
                        }

                        myds.Tables.Add(BP.Sys.PubClass.GetDataTableByUIBineKey(uiBindKey));
                    }
                    #endregion 外键字段
                }
                #endregion 从表的 外键表/枚举
            }
            #endregion 加载 从表表单模版信息.(含 从表的枚举/外键相关数据)

            #endregion 表单模版信息.(含主、从表的,以及从表的枚举/外键相关数据).

            #region 主表数据
            if (BP.Sys.SystemConfig.IsBSsystem == true)
            {
                // 处理传递过来的参数。
                foreach (string k in System.Web.HttpContext.Current.Request.QueryString.AllKeys)
                {
                    wk.SetValByKey(k, System.Web.HttpContext.Current.Request.QueryString[k]);
                }
            }

            // 执行表单事件..
            string msg = md.DoEvent(FrmEventList.FrmLoadBefore, wk);
            if (DataType.IsNullOrEmpty(msg) == false)
            {
                throw new Exception("err@错误:" + msg);
            }

            //重设默认值.
            wk.ResetDefaultVal();

            //执行装载填充.
            me = new MapExt();

            if (me.Retrieve(MapExtAttr.ExtType, MapExtXmlList.PageLoadFull, MapExtAttr.FK_MapData, frmID) == 1)
            {
                //执行通用的装载方法.
                MapAttrs attrs = new MapAttrs(frmID);
                MapDtls  dtls  = new MapDtls(frmID);
                wk = BP.WF.Glo.DealPageLoadFull(wk, me, attrs, dtls) as GEEntity;
            }

            //增加主表数据.
            DataTable mainTable = wk.ToDataTableField(md.No);
            mainTable.TableName = "MainTable";
            myds.Tables.Add(mainTable);

            #endregion 主表数据

            #region  从表数据
            foreach (MapDtl dtl in md.MapDtls)
            {
                #region 返回指定的明细表的数据.
                if (DataType.IsNullOrEmpty(specDtlFrmID) == true)
                {
                }
                else
                {
                    if (dtl.No != specDtlFrmID)
                    {
                        continue;
                    }
                }
                #endregion 返回指定的明细表的数据.

                GEDtls      dtls = new GEDtls(dtl.No);
                QueryObject qo   = null;
                try
                {
                    qo = new QueryObject(dtls);
                    switch (dtl.DtlOpenType)
                    {
                    case DtlOpenType.ForEmp:                              // 按人员来控制.
                        qo.AddWhere(GEDtlAttr.RefPK, pkval);
                        qo.addAnd();
                        qo.AddWhere(GEDtlAttr.Rec, WebUser.No);
                        break;

                    case DtlOpenType.ForWorkID:                             // 按工作ID来控制
                        qo.AddWhere(GEDtlAttr.RefPK, pkval);
                        break;

                    case DtlOpenType.ForFID:                             // 按流程ID来控制.
                        qo.AddWhere(GEDtlAttr.FID, pkval);
                        break;
                    }
                }
                catch
                {
                    dtls.GetNewEntity.CheckPhysicsTable();
                }

                //条件过滤.
                if (dtl.FilterSQLExp != "")
                {
                    string[] strs = dtl.FilterSQLExp.Split('=');
                    qo.addAnd();
                    qo.AddWhere(strs[0], strs[1]);
                }

                //从表
                DataTable dtDtl = qo.DoQueryToTable();

                // 为明细表设置默认值.
                MapAttrs dtlAttrs = new MapAttrs(dtl.No);
                foreach (MapAttr attr in dtlAttrs)
                {
                    //处理它的默认值.
                    if (attr.DefValReal.Contains("@") == false)
                    {
                        continue;
                    }

                    foreach (DataRow dr in dtDtl.Rows)
                    {
                        dr[attr.KeyOfEn] = attr.DefVal;
                    }
                }

                dtDtl.TableName = string.IsNullOrWhiteSpace(dtl.Alias) ? dtl.No : dtl.Alias; //edited by liuxc,2017-10-10.如果有别名,则使用别名,没有则使用No
                myds.Tables.Add(dtDtl);                                                      //加入这个明细表, 如果没有数据,xml体现为空.
            }
            #endregion 从表数据

            #region 主表的 外键表/枚举
            dtMapAttr = myds.Tables["Sys_MapAttr"];
            mes       = md.MapExts;
            foreach (DataRow dr in dtMapAttr.Rows)
            {
                string uiBindKey = dr["UIBindKey"].ToString();
                string myPK      = dr["MyPK"].ToString();
                string lgType    = dr["LGType"].ToString();
                if (lgType.Equals("1"))
                {
                    // 如果是枚举值, 判断是否存在.,
                    if (myds.Tables.Contains(uiBindKey) == true)
                    {
                        continue;
                    }

                    string    mysql  = "SELECT IntKey AS No, Lab as Name FROM Sys_Enum WHERE EnumKey='" + uiBindKey + "' ORDER BY IntKey ";
                    DataTable dtEnum = DBAccess.RunSQLReturnTable(mysql);
                    dtEnum.TableName = uiBindKey;
                    myds.Tables.Add(dtEnum);
                    continue;
                }

                if (lgType.Equals("2") == false)
                {
                    continue;
                }

                string UIIsEnable = dr["UIIsEnable"].ToString();
                if (UIIsEnable.Equals("0"))
                {
                    continue;
                }

                // 检查是否有下拉框自动填充。
                string keyOfEn    = dr["KeyOfEn"].ToString();
                string fk_mapData = dr["FK_MapData"].ToString();

                #region 处理下拉框数据范围. for 小杨.
                me = mes.GetEntityByKey(MapExtAttr.ExtType, MapExtXmlList.AutoFullDLL, MapExtAttr.AttrOfOper, keyOfEn) as MapExt;
                if (me != null)
                {
                    string fullSQL = me.Doc.Clone() as string;
                    fullSQL      = fullSQL.Replace("~", ",");
                    fullSQL      = BP.WF.Glo.DealExp(fullSQL, wk, null);
                    dt           = DBAccess.RunSQLReturnTable(fullSQL);
                    dt.TableName = myPK;                     //可能存在隐患,如果多个字段,绑定同一个表,就存在这样的问题.
                    myds.Tables.Add(dt);
                    continue;
                }
                #endregion 处理下拉框数据范围.

                dt           = BP.Sys.PubClass.GetDataTableByUIBineKey(uiBindKey);
                dt.TableName = uiBindKey;
                myds.Tables.Add(dt);
            }
            #endregion 主表的 外键表/枚举

            //返回生成的dataset.
            return(myds);
        }
Esempio n. 5
0
        /// <summary>
        /// 生成要返回给page的Json数据.
        /// </summary>
        /// <param name="fk_md"></param>
        /// <param name="en"></param>
        public void LoadFrmData(string fk_md, Entity en)
        {
            var dictParams = new ReplaceFieldList(); //主表参数值集合
            var fields     = new List <string>();    // 主表参数名集合

            dictParams.Add("No", WebUser.No, "string");
            dictParams.Add("Name", WebUser.Name, "string");
            dictParams.Add("FK_Dept", WebUser.FK_Dept, "string");
            dictParams.Add("FK_DeptName", WebUser.FK_DeptName, "string");

            var    mes  = new MapExts(fk_md);
            MapExt item = mes.GetEntityByKey(MapExtAttr.ExtType, MapExtXmlList.PageLoadFull) as MapExt;
            //把数据装载到表里,包括从表数据,主表数据未存储.
            MapDtls  dtls   = new MapDtls(fk_md);
            MapAttrs mattrs = new MapAttrs(fk_md);

            en = BP.WF.Glo.DealPageLoadFull(en, item, mattrs, dtls); // 处理表单装载数据.

            //MapData md=new MapData(this.FK_MapData);
            foreach (MapAttr mapattr in mattrs)
            {
                fields.Add(mapattr.KeyOfEn);
                dictParams.Add(mapattr.KeyOfEn, en.GetValStringByKey(mapattr.KeyOfEn), mapattr.IsSigan ? "sign" : "string");
            }

            ReplaceParams += firsts[fk_md] ? GenerateParamsJsonString(dictParams) : "[]";

            //生成json格式。
            ReplaceFields += GenerateFieldsJsonString(fields);

            if (item == null || string.IsNullOrEmpty(item.Tag1) ||
                item.Tag1.Length < 15)
            {
                ReplaceDtls   += "[]";
                ReplaceDtlNos += "[]";
                return;
            }

            var       replaceDtlNos = new List <string>();
            DataSet   ds            = new DataSet();
            DataTable table         = null;
            var       sql           = string.Empty;
            var       pk            = GetPK(fk_md);

            // 填充从表.
            foreach (MapDtl dtl in dtls)
            {
                replaceDtlNos.Add(dtl.No);

                if (!firsts[fk_md])
                {
                    continue;
                }

                sql             = "SELECT * FROM " + dtl.PTable + " WHERE RefPK='" + pk + "'";
                table           = BP.DA.DBAccess.RunSQLReturnTable(sql);
                table.TableName = dtl.No;
                ds.Tables.Add(table);
            }

            // 从表数据.
            ReplaceDtls   += firsts[fk_md] ? BP.DA.DataTableConvertJson.Dataset2Json(ds) : "[]";
            ReplaceDtlNos += GenerateFieldsJsonString(replaceDtlNos);
        }
Esempio n. 6
0
        /// <summary>
        /// 保存从word中提取的数据
        /// <param name="fk_mds">excel表单的编号</param>
        /// </summary>
        private void SaveFieldInfos(string[] fk_mds)
        {
            foreach (var fk_md in fk_mds)
            {
                var mes = new MapExts(fk_md);
                if (mes.Count == 0)
                {
                    return;
                }

                var item = mes.GetEntityByKey(MapExtAttr.ExtType, MapExtXmlList.PageLoadFull) as MapExt;
                if (item == null)
                {
                    return;
                }

                var fieldCount = 0;
                var prefix     = "field_" + fk_md;
                foreach (var key in Request.Form.AllKeys)
                {
                    var idx = 0;
                    if (key.StartsWith(prefix) && key.Length > prefix.Length && int.TryParse(key.Substring(prefix.Length), out idx))
                    {
                        fieldCount++;
                    }
                }

                var fieldsJson = string.Empty;
                for (var i = 0; i < fieldCount; i++)
                {
                    fieldsJson += Request[prefix + i];
                }

                //var fieldsJson = Request["field"];
                var fields = LitJson.JsonMapper.ToObject <List <ReplaceField> >(HttpUtility.UrlDecode(fieldsJson));

                //更新主表数据
                var en = new GEEntityExcelFrm(fk_md);
                var pk = en.OID = GetPK(fk_md);

                if (en.RetrieveFromDBSources() == 0)
                {
                    throw new Exception("OID=" + pk + "的数据在" + fk_md + "中不存在,请检查!");
                }

                //此处因为weboffice在上传的接口中,只有上传成功与失败的返回值,没有具体的返回信息参数,所以未做异常处理
                foreach (var field in fields)
                {
                    en.SetValByKey(field.key, field.value);
                }

                en.LastEditer = WebUser.Name;
                en.RDT        = DataType.CurrentDataTime;
                en.Update();

                //todo:更新明细表数据,此处逻辑可能还有待商榷
                var mdtls = new MapDtls(fk_md);
                if (mdtls.Count == 0)
                {
                    return;
                }

                var dtlsCount = 0;
                prefix = "dtls_" + fk_md;
                foreach (var key in Request.Form.AllKeys)
                {
                    var idx = 0;
                    if (key.StartsWith(prefix) && key.Length > prefix.Length && int.TryParse(key.Substring(prefix.Length), out idx))
                    {
                        dtlsCount++;
                    }
                }

                var dtlsJson = string.Empty;
                for (var i = 0; i < dtlsCount; i++)
                {
                    dtlsJson += Request[prefix + i];
                }

                //var dtlsJson = Request["dtls"];
                var             dtls   = LitJson.JsonMapper.ToObject <List <ReplaceDtlTable> >(HttpUtility.UrlDecode(dtlsJson));
                GEDtls          gedtls = null;
                GEDtl           gedtl  = null;
                ReplaceDtlTable wdtl   = null;

                foreach (MapDtl mdtl in mdtls)
                {
                    wdtl = dtls.FirstOrDefault(o => o.dtlno == mdtl.No);

                    if (wdtl == null || wdtl.dtl.Count == 0)
                    {
                        continue;
                    }

                    //此处不是真正意义上的更新,因为不知道明细表的主键,只能将原明细表中的数据删除掉,然后再重新插入新的数据
                    gedtls = new GEDtls(mdtl.No);
                    gedtls.Delete(GEDtlAttr.RefPK, en.PKVal);

                    foreach (var d in wdtl.dtl)
                    {
                        gedtl = gedtls.GetNewEntity as GEDtl;

                        foreach (var cell in d.cells)
                        {
                            gedtl.SetValByKey(cell.key, cell.value);
                        }

                        gedtl.RefPK = en.PKVal.ToString();
                        gedtl.RDT   = DataType.CurrentDataTime;
                        gedtl.Rec   = WebUser.No;
                        gedtl.Insert();
                    }
                }
            }
        }
Esempio n. 7
0
        public void LoadFrmData(MapAttrs mattrs, Entity en)
        {
            var mes        = new MapExts(this.FK_MapData);
            var dictParams = new ReplaceFieldList();
            var fields     = new List <string>();

            dictParams.Add("No", WebUser.No, "string");
            dictParams.Add("Name", WebUser.Name, "string");
            dictParams.Add("FK_Dept", WebUser.FK_Dept, "string");
            dictParams.Add("FK_DeptName", WebUser.FK_DeptName, "string");

            if (mes.Count == 0)
            {
                ReplaceParams = GenerateParamsJsonString(dictParams);
                ReplaceFields = "[]";
                ReplaceDtlNos = "[]";
                ReplaceDtls   = "[]";
                return;
            }

            MapExt item = mes.GetEntityByKey(MapExtAttr.ExtType, MapExtXmlList.PageLoadFull) as MapExt;

            if (item == null)
            {
                ReplaceParams = GenerateParamsJsonString(dictParams);
                ReplaceFields = "[]";
                ReplaceDtlNos = "[]";
                ReplaceDtls   = "[]";
                return;
            }

            DataTable dt    = null;
            MapAttr   mattr = null;
            string    sql   = item.Tag;

            if (string.IsNullOrEmpty(sql) == false)
            {
                /* 如果有填充主表的sql  */
                #region 处理sql变量
                sql = sql.Replace("@WebUser.No", WebUser.No);
                sql = sql.Replace("@WebUser.Name", WebUser.Name);
                sql = sql.Replace("@WebUser.FK_Dept", WebUser.FK_Dept);
                sql = sql.Replace("@WebUser.FK_DeptName", WebUser.FK_DeptName);

                foreach (MapAttr attr in mattrs)
                {
                    if (sql.Contains("@"))
                    {
                        sql = sql.Replace("@" + attr.KeyOfEn, en.GetValStrByKey(attr.KeyOfEn));
                    }
                    else
                    {
                        break;
                    }
                }
                #endregion 处理sql变量

                if (string.IsNullOrEmpty(sql) == false)
                {
                    if (sql.Contains("@"))
                    {
                        throw new Exception("设置的sql有错误可能有没有替换的变量:" + sql);
                    }
                    dt = DBAccess.RunSQLReturnTable(sql);
                    if (dt.Rows.Count == 1)
                    {
                        DataRow dr = dt.Rows[0];
                        foreach (DataColumn dc in dt.Columns)
                        {
                            en.SetValByKey(dc.ColumnName, dr[dc.ColumnName].ToString());

                            mattr = mattrs.GetEntityByKey(MapAttrAttr.KeyOfEn, dc.ColumnName) as MapAttr;

                            dictParams.Add(dc.ColumnName, dr[dc.ColumnName].ToString(), mattr != null && mattr.IsSigan ? "sign" : "string");
                            fields.Add(dc.ColumnName);
                        }
                    }
                }
            }

            if (IsFirst)
            {
                ReplaceParams = GenerateParamsJsonString(dictParams);
            }
            else
            {
                ReplaceParams = "[]";
            }

            ReplaceFields = GenerateFieldsJsonString(fields);

            if (string.IsNullOrEmpty(item.Tag1) ||
                item.Tag1.Length < 15)
            {
                ReplaceDtls   = "[]";
                ReplaceDtlNos = "[]";
                return;
            }

            ReplaceDtls   = "[";
            ReplaceDtlNos = "[";
            MapDtls dtls = new MapDtls(this.FK_MapData);
            // 填充从表.
            foreach (MapDtl dtl in dtls)
            {
                ReplaceDtlNos += "\"" + dtl.No + "\",";

                if (!IsFirst)
                {
                    continue;
                }

                string[] sqls = item.Tag1.Split('*');
                foreach (string mysql in sqls)
                {
                    if (string.IsNullOrEmpty(mysql))
                    {
                        continue;
                    }

                    if (mysql.Contains(dtl.No + "=") == false)
                    {
                        continue;
                    }

                    #region 处理sql.
                    sql = mysql;
                    sql = sql.Replace(dtl.No + "=", "");
                    sql = sql.Replace("@WebUser.No", WebUser.No);
                    sql = sql.Replace("@WebUser.Name", WebUser.Name);
                    sql = sql.Replace("@WebUser.FK_Dept", WebUser.FK_Dept);
                    sql = sql.Replace("@WebUser.FK_DeptName", WebUser.FK_DeptName);
                    foreach (MapAttr attr in mattrs)
                    {
                        if (sql.Contains("@"))
                        {
                            sql = sql.Replace("@" + attr.KeyOfEn, en.GetValStrByKey(attr.KeyOfEn));
                        }
                        else
                        {
                            break;
                        }
                    }
                    #endregion 处理sql.

                    if (string.IsNullOrEmpty(sql))
                    {
                        continue;
                    }

                    if (sql.Contains("@"))
                    {
                        throw new Exception("设置的sql有错误可能有没有替换的变量:" + sql);
                    }

                    GEDtls gedtls = new GEDtls(dtl.No);

                    try
                    {
                        gedtls.Delete(GEDtlAttr.RefPK, en.PKVal);
                    }
                    catch
                    {
                        gedtls.GetNewEntity.CheckPhysicsTable();
                    }

                    dt = DBAccess.RunSQLReturnTable(sql);
                    //dictDtls.Add(dtl.No, dt);
                    ReplaceDtls += "{\"dtlno\":\"" + dtl.No + "\",\"dtl\":[";
                    var idx = 1;
                    foreach (DataRow dr in dt.Rows)
                    {
                        ReplaceDtls += "{\"rowid\":" + (idx++) + ",\"cells\":[";
                        GEDtl gedtl = gedtls.GetNewEntity as GEDtl;

                        foreach (DataColumn dc in dt.Columns)
                        {
                            gedtl.SetValByKey(dc.ColumnName, dr[dc.ColumnName].ToString());

                            mattr = dtl.MapAttrs.GetEntityByKey(MapAttrAttr.KeyOfEn, dc.ColumnName) as MapAttr;

                            ReplaceDtls += "{\"key\":\"" + dc.ColumnName + "\",\"value\":\"" + dr[dc.ColumnName] + "\",\"type\":\"" + (mattr != null && mattr.IsSigan ? "sign" : "string") + "\"},";
                        }

                        ReplaceDtls = ReplaceDtls.TrimEnd(',') + "]},";
                        gedtl.RefPK = en.PKVal.ToString();
                        gedtl.RDT   = DataType.CurrentDataTime;
                        gedtl.Rec   = WebUser.No;
                        gedtl.Insert();
                    }

                    ReplaceDtls = ReplaceDtls.TrimEnd(',') + "]}";
                }
            }

            ReplaceDtls   = ReplaceDtls.TrimEnd(',') + "]";
            ReplaceDtlNos = ReplaceDtlNos.TrimEnd(',') + "]";
        }