智遥工作流为Sap报工时(实例)

报工时程序,是很常见的系统,几乎每个工厂都会使用到。由于SAP账号昂贵,一般企业不会给每个人都开通一个账号进去报工时,而是使用一个公共账号进去报工时;但是这样做往往有不好做权限管控,及时大家都用一个账号,也还是得占用一个账号,成本较高。而且SAP开发类似程序比较麻烦。

最近有一客户就直接使用智遥工作流,进行扩展,做了一个SAP报工时程序。操作方便,简洁,效果不错。

程序要求及开发关键代码:

1.先点击查询,将需要报工时的项目从SAP系统中查找出来

string[] param = { "WERKS_FROM|"+WERKS_FROM,
                                    "PRCTR_FROM|"+PRCTR_FROM,
                                    "GSTRP_FROM|"+GSTRP_FROM,
                                    "AUFNR_FROM|"+AUFNR_FROM,
                                    "MATNR_FROM|"+MATNR_FROM,
                                    "WERKS_TO|"+WERKS_TO,
                                    "PRCTR_TO|"+PRCTR_TO,
                                    "GSTRP_TO|"+GSTRP_TO,
                                    "AUFNR_TO|"+AUFNR_TO,
                                    "MATNR_TO|"+MATNR_TO
                                    };
                DataTable dt_AFPO = r.GetSapTable(param, "BAPI_PDO_LIST", "I_AFPO" );//获取查询项目信息
                DataTable dt_AFVC = r.GetSapTable(param, "BAPI_PDO_LIST", "I_AFVC");//获取工艺明细信息
//遍历 table 将数据写入本地数据库中
.....................

2.点击项目,显示出项目的工序信息

3.然后为每个工序报工时,每个工序,可以报多条记录

先将填报的工时数据,存入本地的数据库中。

4.所有报工时项目,填报完成后,点击“保存至SAP”,将数据一次性导入到SAP。

查询数据库,将报的工时数据查出来,调用SAP RFC,将数据导入SAP

传入SAP的table 结构和列名,要和SAP 中相对应的内表完全一致,否则会出错。

protected void BUpload_Click(object sender, DirectEventArgs e) 
        {
         
            StringBuilder sqlstr = new StringBuilder();
            sqlstr.Append("Select  H.AUFNR,H.VORNR,H.WORK_CENTER AS ARBPL");
            sqlstr.Append(",ISNULL(D.YIELD,0) AS YIELD,ISNULL(D.SCRAP,0) AS SCRAP,ISNULL(D.REWORK,0) AS REWORK,ISNULL(D.VORME_Q,0) AS VORME_Q,ISNULL(D.SETUP,0) AS SETUP,ISNULL(D.MACHINE,0) AS MACHINE,ISNULL(D.LABOR,0) AS LABOR,ISNULL(D.BREAK_TIME,0) AS BREAK_TIME,ISNULL(D.VORME_T,0) AS VORME_T,ISNULL(D.REASON,'') AS REASON,CONVERT(VARCHAR(8),D.PDATE,112) AS PDATE,'" + u.GetLoginID() + "'+'|'+isnull(D.LB,'')+'|'+isnull(D.BC,'')+'|'+ ISNULL(D.[TEXT],'') AS [TEXT] ");
            sqlstr.Append(",D.GSID AS ID ,'" + u.GetLoginID() + "' AS ERNAM ");
            sqlstr.Append(" From SAP_ZPDO_AFVC H ");
            sqlstr.Append(" INNER JOIN SAP_ZPDO_GS D ON H.ID=D.ID ");
            sqlstr.Append(" Where H.CREATOR='" + u.GetLoginID() + "'");
            sqlstr.Append(" ");
            
            SapRFC_DEV SR = new SapRFC_DEV();            
            DataTable dt = SI.QuerySql(sqlstr.ToString());//查出报的工时数据
            if (dt.Rows.Count > 0)
            {
         //将数据传入SAP,并获取返回信息(如果有不成功的记录,会被返回) DataTable dtr
= SR.ExecuteRfc_InputITtable(dt, "BAPI_CO11N", "I_AFRU", "BAPI_CO11N", "I_AFRU"); string xx = ""; string idStr = ""; int id = 0; for (int i = 0; i < dtr.Rows.Count; i++) { xx = xx+dtr.rows[i][0].ToString()+"<br />"; } BindStore3(); if (xx.Trim() == "") { xx = "上传成功!"; } X.Msg.Alert("提示:", xx).Show(); } }

 有图有真相:

SAP报工时截图

 

posted @ 2013-05-24 16:55  workflower  阅读(1792)  评论(0编辑  收藏  举报