Exemplo n.º 1
0
        public Boolean ProcessInvoice(String databaseName, String xmlContent)
        {
            Boolean returnValue = true;
            String  errorMessage;
            String  documentNumber;

            try
            {
                DocumentCached invoice;
                if (!GetInvoiceFromXML(databaseName, xmlContent, out invoice, out errorMessage))
                {
                    Trace.WriteLine(String.Format("Unable to get Invoice from XML. Error: {0}", errorMessage), "ProcessInvoice");
                    returnValue = false;
                }

                if (!ImportInvoice(databaseName, invoice, out documentNumber, out errorMessage))
                {
                    Trace.WriteLine(String.Format("Unable to create Invoice in SAP ECC6. Error: {0}", errorMessage), "ProcessInvoice");
                    returnValue = false;
                }
            }
            finally
            {
                RfcDestinationManager.UnregisterDestinationConfiguration(con);
            }

            if (returnValue)
            {
                Trace.WriteLine(String.Format("Created Invoice {0} in SAP ECC6 succesfully! ", documentNumber), "ProcessInvoice");
            }

            return(returnValue);
        }
Exemplo n.º 2
0
        public IRfcTable Rfc_Qdt_Dal(RFC_QDT_Model qdtModel, out RFC_IN_Message rfcMessage)
        {
            rfcMessage = new RFC_IN_Message();
            try
            {
                _configurationId = new RFC_SetUp();
                RfcDestinationManager.RegisterDestinationConfiguration(_configurationId);
                _dest       = RfcDestinationManager.GetDestination("SAPMS");
                _repository = _dest.Repository;
                IRfcFunction rfc   = _repository.CreateFunction(qdtModel.FunctionModule); //调用函数名
                IRfcTable    table = rfc.GetTable(qdtModel.E_SAP_QDT);                    //RFC表数据
                rfc.SetValue("I_MESKEY", qdtModel.I_MESKEY);                              //KEY随机号 不能重复
                rfc.SetValue("I_USER", qdtModel.I_USER);                                  //登录名
                rfc.SetValue("I_MATNR", qdtModel.I_MATNR);
                rfc.SetValue("I_CHARG", qdtModel.I_CHARG);
                rfc.Invoke(_dest);

                rfcMessage.E_RETURN_CODE    = rfc.GetString("E_RETURN_CODE").ToString();
                rfcMessage.E_RETURN_MESSAGE = rfc.GetString("E_RETURN_MESSAGE").ToString();
                rfcMessage.E_COUNT          = rfc.GetInt("E_COUNT").ToString();
                rfcMessage.E_SUM            = rfc.GetInt("E_SUM").ToString();
                return(table);
            }
            catch (Exception exception)
            {
                rfcMessage.E_RETURN_MESSAGE = "接口QDT 错误:" + exception.ToString();
                return(null);
            }
            finally
            {
                RfcDestinationManager.UnregisterDestinationConfiguration(_configurationId);
            }
        }
Exemplo n.º 3
0
 public Rfc_Frota()
 {
     try
     {
         SAPConnect objcon = new SAPConnect();
         RfcDestinationManager.RegisterDestinationConfiguration(objcon);
         dest = RfcDestinationManager.GetDestination("Frota");
         repo = dest.Repository;
         RfcDestinationManager.UnregisterDestinationConfiguration(objcon);
     }
     catch (RfcCommunicationException e)
     {
         throw e;
     }
     catch (RfcLogonException e)
     {
         throw e;
     }
     catch (RfcAbapRuntimeException e)
     {
         throw e;
     }
     catch (RfcAbapBaseException e)
     {
         throw e;
     }
 }
Exemplo n.º 4
0
        public IRfcTable Rfc_Del_Dal(RFC_DEL_Model delModel, out RFC_IN_Message rfcMessage)
        {
            rfcMessage = new RFC_IN_Message();
            try
            {
                _configurationId = new RFC_SetUp();
                RfcDestinationManager.RegisterDestinationConfiguration(_configurationId);
                _dest       = RfcDestinationManager.GetDestination("SAPMS");
                _repository = _dest.Repository;
                IRfcFunction rfc   = _repository.CreateFunction(delModel.FunctionModule); //调用函数名
                IRfcTable    table = rfc.GetTable(delModel.E_SAP_DEL);                    //RFC表数据
                rfc.SetValue("I_MESKEY", delModel.I_MESKEY);                              //KEY随机号 不能重复
                rfc.SetValue("I_DATE", delModel.I_DATE);                                  //日期
                rfc.SetValue("I_TIME", delModel.I_TIME);                                  //时间
                rfc.SetValue("I_USER", delModel.I_USER);                                  //登录名
                rfc.SetValue("I_VBELN", delModel.I_VBELN);
                rfc.Invoke(_dest);

                rfcMessage.E_RETURN_CODE = rfc.GetString("E_RETURN_CODE").ToString();
                //rfcMessage.E_RETURN_MESSAGE = rfc.GetString("E_RETURN_MESSAGE").ToString();
                rfcMessage.E_COUNT = rfc.GetInt("E_COUNT").ToString();
                rfcMessage.E_SUM   = rfc.GetInt("E_SUM").ToString();
                return(table);
            }
            catch (Exception exception)
            {
                rfcMessage.E_RETURN_MESSAGE = "接口DEL 错误:" + exception.ToString();
                return(null);
            }
            finally
            {
                RfcDestinationManager.UnregisterDestinationConfiguration(_configurationId);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 测试连接SAP
        /// </summary>
        /// <returns></returns>
        public bool ConnSap(out string message)
        {
            bool result = false;

            try
            {
                IDestinationConfiguration ID = new RFC_SetUp();
                RfcDestinationManager.RegisterDestinationConfiguration(ID);
                RfcDestination destination = RfcDestinationManager.GetDestination("SAPMS");
                RfcRepository  repository  = destination.Repository;
                IRfcFunction   rfcFunction = repository.CreateFunction("Z_TEST_CONNECTION");
                rfcFunction.Invoke(destination);
                message = rfcFunction.GetValue("E_RETURN_MESSAGE").ToString();
                result  = !(rfcFunction.GetValue("E_RETURN_CODE").ToString() == "E");
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            finally
            {
                RfcDestinationManager.UnregisterDestinationConfiguration(ID);
            }
            return(result);
        }
Exemplo n.º 6
0
 public Dictionary <String, Object> TestConnection()
 {
     try
     {
         RfcDestinationManager.RegisterDestinationConfiguration(this.SAPConfig);
         var           rfcDest = RfcDestinationManager.GetDestination(this.ConfigurationName);
         RfcRepository rfcRep  = null;
         rfcRep = rfcDest.Repository;
     }
     catch (RfcLogonException le)
     {
         return(new Dictionary <string, object>()
         {
             { "Response", false }, { "Message", le.Message }
         });
     }
     catch (Exception ex)
     {
         return(new Dictionary <string, object>()
         {
             { "Response", false }, { "Message", ex.Message + " : " + ex.StackTrace }
         });
     }
     finally
     {
         RfcDestinationManager.UnregisterDestinationConfiguration(this.SAPConfig);
     }
     return(new Dictionary <string, object>()
     {
         { "Response", true }, { "Message", "Success" }
     });
 }
Exemplo n.º 7
0
        public IRfcTable Rfc_Stock_dal(RFC_STOCK_Model StockModel, out RFC_IN_Message rfcMessage)
        {
            rfcMessage = new RFC_IN_Message();
            try
            {
                _configurationId = new RFC_SetUp();
                RfcDestinationManager.RegisterDestinationConfiguration(_configurationId);
                _dest       = RfcDestinationManager.GetDestination("SAPMS");
                _repository = _dest.Repository;
                IRfcFunction rfc   = _repository.CreateFunction(StockModel.FunctionModule); //调用函数名
                IRfcTable    table = rfc.GetTable(StockModel.L_MM_STOCK);                   //RFC表数据
                rfc.SetValue("I_FLAG", "J");
                rfc.Invoke(_dest);

                rfcMessage.E_RETURN_CODE    = rfc.GetString("E_SUBRC").ToString();
                rfcMessage.E_RETURN_MESSAGE = rfc.GetString("E_MESSAGE").ToString();
                return(table);
            }
            catch (Exception exception)
            {
                rfcMessage.E_RETURN_MESSAGE = "接口STOCK错误:" + exception.ToString();
                return(null);
            }
            finally
            {
                RfcDestinationManager.UnregisterDestinationConfiguration(_configurationId);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Commit/Rollback existing transaction.
        /// Unregister current destination configuration.
        /// </summary>
        public void Dispose()
        {
            if (_destinationConfiguration != null)
            {
                if (CurrentTransaction != null)
                {
                    try
                    {
                        CurrentTransaction.Commit();

                        CurrentTransaction = null;
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError(
                            "An error occurred when trying to commit current open transaction. Exception: {0}", ex);
                    }
                }

                try
                {
                    RfcDestinationManager.UnregisterDestinationConfiguration(_destinationConfiguration);
                }
                catch (Exception ex)
                {
                    Trace.TraceError("An error occurred when trying to unregister destination configuration. Exception: {0}", ex);
                }
            }

            GC.SuppressFinalize(this);
        }
Exemplo n.º 9
0
        public Dictionary <String, Object> GetSAPIVAMat(Int64 MaterialId)
        {
            Dictionary <String, Object> response = null;

            try
            {
                var config          = System.Configuration.ConfigurationManager.GetSection(ConfigurationName.Trim()) as NameValueCollection;
                var resultSeparator = config["ResultSeparator"].ToCharArray()[0];
                RfcDestinationManager.RegisterDestinationConfiguration(this.SAPConfig);
                RfcDestination rfcDest = RfcDestinationManager.GetDestination(this.ConfigurationName);
                RfcRepository  rfcRep  = null;
                rfcRep = rfcDest.Repository;
                IRfcFunction qry = rfcRep.CreateFunction("RFC_READ_TABLE");
                qry.SetValue("QUERY_TABLE", "MLAN");
                qry.SetValue("DELIMITER", resultSeparator);
                IRfcTable FIELDS = qry.GetTable("FIELDS");
                FIELDS.Append();
                FIELDS.SetValue("FIELDNAME", "TAXM1");
                IRfcTable OPTIONS = qry.GetTable("OPTIONS");
                OPTIONS.Append();
                OPTIONS.SetValue("TEXT", "MATNR EQ '" + CompleteCodes(MaterialId.ToString(), 18) + "' AND");
                OPTIONS.Append();
                OPTIONS.SetValue("TEXT", "ALAND EQ 'CO'");
                IRfcTable DATA = qry.GetTable("DATA");
                qry.Invoke(rfcDest);
                response = new Dictionary <string, object>();
                if (DATA.ToList().Count > 0)
                {
                    var result = DATA.ToList().First()["WA"];
                    var value  = result.GetValue();
                    response.Add("Response", true);
                    response.Add("SAPIVAMat", value.ToString());
                }
                else
                {
                    response.Add("Response", false);
                }
            }

            catch (RfcLogonException le)
            {
                return(new Dictionary <string, object>()
                {
                    { "Response", false }, { "Message", le.Message }
                });
            }
            catch (Exception ex)
            {
                return(new Dictionary <string, object>()
                {
                    { "Response", false }, { "Message", ex.Message + " : " + ex.StackTrace }
                });
            }
            finally
            {
                RfcDestinationManager.UnregisterDestinationConfiguration(this.SAPConfig);
            }
            return(response);
        }
Exemplo n.º 10
0
        public RFC_OUT_Message Rfc_Rmu_Dal(List <RFC_RMU_Model.RFC_RMU_ITEM_Model> rmuItemModel, RFC_RMU_Model.RFC_RMU_HEADER_Model rmuHeaderModel)
        {
            RFC_OUT_Message rfcMessage = new RFC_OUT_Message();

            try
            {
                _configurationId = new RFC_SetUp();
                RfcDestinationManager.RegisterDestinationConfiguration(_configurationId);
                _dest       = RfcDestinationManager.GetDestination("SAPMS");
                _repository = _dest.Repository;
                IRfcFunction  rfc       = _repository.CreateFunction("Z_PP_MES_OUT_RMU"); //调用函数名
                IRfcTable     table     = rfc.GetTable(rmuHeaderModel.E_SAP_RMU);         //RFC表数据
                IRfcStructure structure = rfc.GetStructure("I_HEADER");                   //RFC表头数据
                structure.SetValue("ZMESKEY", rmuHeaderModel.ZMESKEY);
                structure.SetValue("BLDAT", rmuHeaderModel.BLDAT);
                structure.SetValue("BUDAT", rmuHeaderModel.BUDAT);
                structure.SetValue("ZCOUNT", rmuHeaderModel.ZCOUNT);
                structure.SetValue("ZUSER", rmuHeaderModel.ZUSER);
                structure.SetValue("ZUNPLAN", rmuHeaderModel.ZUNPLAN);
                try
                {
                    structure.SetValue("BKTXT", rmuHeaderModel.BKTXT);
                }
                catch  {}

                foreach (var _rmuItemModel in rmuItemModel)
                {
                    table.Insert();
                    table.CurrentRow.SetValue("ZMESITEM", _rmuItemModel.ZMESITEM);
                    table.CurrentRow.SetValue("AUFNR", _rmuItemModel.AUFNR);
                    table.CurrentRow.SetValue("POSNR", _rmuItemModel.POSNR);
                    table.CurrentRow.SetValue("BWART", _rmuItemModel.BWART);
                    table.CurrentRow.SetValue("MATNR", _rmuItemModel.MATNR);
                    table.CurrentRow.SetValue("WERKS", _rmuItemModel.WERKS);
                    table.CurrentRow.SetValue("LGORT", _rmuItemModel.LGORT);
                    table.CurrentRow.SetValue("MENGE", _rmuItemModel.MENGE);
                    table.CurrentRow.SetValue("MEINS", _rmuItemModel.MEINS);
                    table.CurrentRow.SetValue("CHARG", _rmuItemModel.CHARG);
                    table.CurrentRow.SetValue("ITEM_TEXT", _rmuItemModel.ITEM_TEXT);

                    // rmuHeaderModel.ZSUM += _rmuItemModel.MENGE;//所有数据全部相加,取总数
                }
                structure.SetValue("ZSUM", rmuHeaderModel.ZSUM);
                rfc.Invoke(_dest);
                rfcMessage.E_RETURN_CODE    = rfc.GetString("E_RETURN_CODE").ToString();
                rfcMessage.E_RETURN_MESSAGE = rfc.GetString("E_RETURN_MESSAGE").ToString();
                rfcMessage.E_EXPROC         = rfc.GetString("E_MAT_DOC").ToString();
                return(rfcMessage);
            }
            catch (Exception exception)
            {
                rfcMessage.E_RETURN_MESSAGE = "接口RMU 错误:" + exception.ToString();
                return(null);
            }
            finally
            {
                RfcDestinationManager.UnregisterDestinationConfiguration(_configurationId);
            }
        }
Exemplo n.º 11
0
        public RFC_OUT_Message  Rfc_Fgo_Dal(List <RFC_FGO_Model.RFC_FGO_ITEM_Model> fgoItemModel, RFC_FGO_Model.RFC_FGO_HEADER_Model fgoHeaderModel)
        {
            RFC_OUT_Message rfcMessage = new RFC_OUT_Message();

            try
            {
                _configurationId = new RFC_SetUp();
                RfcDestinationManager.RegisterDestinationConfiguration(_configurationId);
                _dest       = RfcDestinationManager.GetDestination("SAPMS");
                _repository = _dest.Repository;
                IRfcFunction  rfc       = _repository.CreateFunction("Z_PP_MES_OUT_FGO"); //调用函数名
                IRfcTable     table     = rfc.GetTable("T_DATA");                         //RFC表数据
                IRfcStructure structure = rfc.GetStructure("I_HEADER");                   //RFC表头数据
                structure.SetValue("ZMESKEY", fgoHeaderModel.ZMESKEY);
                structure.SetValue("AUFNR", fgoHeaderModel.AUFNR);
                structure.SetValue("BUDAT", fgoHeaderModel.BUDAT);
                structure.SetValue("ZCOUNT", fgoHeaderModel.ZCOUNT);
                //structure.SetValue("ZSUM", fgoHeaderModel.ZSUM);
                structure.SetValue("ZUSER", fgoHeaderModel.ZUSER);

                fgoHeaderModel.ZSUM = 0;

                foreach (var _fgoItemModel in fgoItemModel)
                {
                    table.Insert();
                    table.CurrentRow.SetValue("ZMESITEM", _fgoItemModel.ZMESITEM);
                    table.CurrentRow.SetValue("BWART", _fgoItemModel.BWART);
                    table.CurrentRow.SetValue("WERKS", _fgoItemModel.WERKS);
                    table.CurrentRow.SetValue("LGORT", _fgoItemModel.LGORT);
                    table.CurrentRow.SetValue("MENGE", _fgoItemModel.MENGE);
                    table.CurrentRow.SetValue("MEINS", _fgoItemModel.MEINS);
                    table.CurrentRow.SetValue("ZINBOXNO_MIN", _fgoItemModel.ZINBOXNO_MIN);
                    table.CurrentRow.SetValue("ZINBOXNO_MAX", _fgoItemModel.ZINBOXNO_MIN);
                    table.CurrentRow.SetValue("ZLOTNO", _fgoItemModel.ZLOTNO);
                    table.CurrentRow.SetValue("ZINBOXNO", _fgoItemModel.ZINBOXNO);
                    fgoHeaderModel.ZSUM += _fgoItemModel.MENGE;//所有数据全部相加,取总数
                }
                structure.SetValue("ZSUM", fgoHeaderModel.ZSUM);
                rfc.Invoke(_dest);
                rfcMessage.E_RETURN_CODE    = rfc.GetString("E_RETURN_CODE").ToString();
                rfcMessage.E_RETURN_MESSAGE = rfc.GetString("E_RETURN_MESSAGE").ToString();
                //rfcMessage.E_PO_NUMBER = rfc.GetInt("E_COUNT").ToString();
                //rfcMessage.E_EXPROC = rfc.GetInt("E_SUM").ToString();
                rfcMessage.E_MAT_DOC = rfc.GetString("E_MAT_DOC").ToString();
                rfcMessage.E_EXPROC  = rfc.GetString("E_EXPROC").ToString();
                return(rfcMessage);
            }
            catch (Exception exception)
            {
                rfcMessage.E_RETURN_MESSAGE = "接口FGO 错误:" + exception.ToString();
                return(null);
            }
            finally
            {
                RfcDestinationManager.UnregisterDestinationConfiguration(_configurationId);
            }
        }
Exemplo n.º 12
0
        public RFC_OUT_Message Rfc_Gpr_Dal(List <RFC_GPR_Model.RFC_GPR_ITEM_Model> gprItemModel, RFC_GPR_Model.RFC_GPR_HEADER_Model gprHeaderModel)
        {
            RFC_OUT_Message rfcMessage = new RFC_OUT_Message();

            try
            {
                _configurationId = new RFC_SetUp();
                RfcDestinationManager.RegisterDestinationConfiguration(_configurationId);
                _dest       = RfcDestinationManager.GetDestination("SAPMS");
                _repository = _dest.Repository;
                IRfcFunction  rfc       = _repository.CreateFunction(gprHeaderModel.FunctionModule); //调用函数名
                IRfcTable     table     = rfc.GetTable(gprHeaderModel.E_SAP_GRP);                    //RFC表数据
                IRfcStructure structure = rfc.GetStructure("I_HEADER");                              //RFC表头数据
                structure.SetValue("ZMESKEY", gprHeaderModel.ZMESKEY);
                structure.SetValue("EBELN", gprHeaderModel.EBELN);
                structure.SetValue("BUKRS", gprHeaderModel.BUKRS);
                structure.SetValue("BSART", gprHeaderModel.BSART);
                structure.SetValue("EKORG", gprHeaderModel.EKORG);
                structure.SetValue("AEDAT", gprHeaderModel.AEDAT);
                structure.SetValue("LIFNR", gprHeaderModel.LIFNR);
                structure.SetValue("ZCOUNT", gprHeaderModel.ZCOUNT);
                structure.SetValue("ZUSER", gprHeaderModel.ZUSER);
                foreach (var _gprItemModel in gprItemModel)
                {
                    table.Insert();
                    table.CurrentRow.SetValue("ZMESITEM", _gprItemModel.ZMESITEM);
                    table.CurrentRow.SetValue("EBELP", _gprItemModel.EBELP);
                    table.CurrentRow.SetValue("LOEKZ", _gprItemModel.LOEKZ);
                    table.CurrentRow.SetValue("MATNR", _gprItemModel.MATNR);
                    table.CurrentRow.SetValue("WERKS", _gprItemModel.WERKS);
                    table.CurrentRow.SetValue("LGORT", _gprItemModel.LGORT);
                    table.CurrentRow.SetValue("MENGE", _gprItemModel.MENGE);
                    table.CurrentRow.SetValue("MEINS", _gprItemModel.MEINS);
                    table.CurrentRow.SetValue("EINDT", _gprItemModel.EINDT);
                    table.CurrentRow.SetValue("LICHA", _gprItemModel.LICHA);
                    table.CurrentRow.SetValue("ZJPSONO", _gprItemModel.ZJPSONO);
                    table.CurrentRow.SetValue("ZJPSOITEM", _gprItemModel.ZJPSOITEM);
                    gprHeaderModel.ZSUM += _gprItemModel.MENGE;//所有数据全部相加,取总数
                }
                structure.SetValue("ZSUM", gprHeaderModel.ZSUM);
                rfc.Invoke(_dest);
                rfcMessage.E_RETURN_CODE = rfc.GetString("E_RETURN_CODE").ToString();
                //rfcMessage.E_RETURN_MESSAGE = rfc.GetString("E_RETURN_MESSAGE").ToString();
                rfcMessage.E_PO_NUMBER = rfc.GetInt("E_COUNT").ToString();
                rfcMessage.E_EXPROC    = rfc.GetInt("E_SUM").ToString();
                return(rfcMessage);
            }
            catch (Exception exception)
            {
                rfcMessage.E_RETURN_MESSAGE = "接口GPR 错误:" + exception.ToString();
                return(null);
            }
            finally
            {
                RfcDestinationManager.UnregisterDestinationConfiguration(_configurationId);
            }
        }
Exemplo n.º 13
0
        public RFC_OUT_Message Rfc_Stu_Dal(List <RFC_STU_Model.RFC_STU_ITEM_Model> stuItemModel, RFC_STU_Model.RFC_STU_HEADER_Model stuHeaderModel)
        {
            RFC_OUT_Message rfcMessage = new RFC_OUT_Message();

            try
            {
                _configurationId = new RFC_SetUp();
                RfcDestinationManager.RegisterDestinationConfiguration(_configurationId);
                _dest       = RfcDestinationManager.GetDestination("SAPMS");
                _repository = _dest.Repository;
                IRfcFunction  rfc       = _repository.CreateFunction(stuHeaderModel.FunctionModule); //调用函数名
                IRfcTable     table     = rfc.GetTable("T_DATA");                                    //RFC表数据
                IRfcStructure structure = rfc.GetStructure("I_HEADER");                              //RFC表头数据
                structure.SetValue("ZMESKEY", stuHeaderModel.ZMESKEY);
                structure.SetValue("BUDAT", stuHeaderModel.BUDAT);
                structure.SetValue("ZCOUNT", stuHeaderModel.ZCOUNT);
                structure.SetValue("ZSUM", stuHeaderModel.ZSUM);
                structure.SetValue("ZUSER", stuHeaderModel.ZUSER);
                structure.SetValue("BKTXT", stuHeaderModel.BKTXT);

                table.Clear();
                foreach (var _stuItemModel in stuItemModel)
                {
                    table.Insert();
                    table.CurrentRow.SetValue("ZMESITEM", _stuItemModel.ZMESITEM);
                    table.CurrentRow.SetValue("BWART", _stuItemModel.BWART);
                    table.CurrentRow.SetValue("MATNR", _stuItemModel.MATNR);
                    table.CurrentRow.SetValue("WERKS", _stuItemModel.WERKS);
                    table.CurrentRow.SetValue("LGORT", _stuItemModel.LGORT);
                    table.CurrentRow.SetValue("MENGE", _stuItemModel.MENGE);
                    table.CurrentRow.SetValue("MEINS", _stuItemModel.MEINS);
                    table.CurrentRow.SetValue("CHARG", _stuItemModel.CHARG);
                    table.CurrentRow.SetValue("ZEILE", _stuItemModel.ZEILE);
                    table.CurrentRow.SetValue("UMLGO", _stuItemModel.UMLGO);
                    table.CurrentRow.SetValue("LIFNR", _stuItemModel.LIFNR);
                    table.CurrentRow.SetValue("SOBKZ", _stuItemModel.SOBKZ);
                    //stuHeaderModel.ZSUM += _stuItemModel.MENGE;//所有数据全部相加,取总数
                }
                structure.SetValue("ZSUM", stuHeaderModel.ZSUM);
                rfc.Invoke(_dest);
                rfcMessage.E_RETURN_CODE    = rfc.GetString("E_RETURN_CODE").ToString();
                rfcMessage.E_RETURN_MESSAGE = rfc.GetString("E_RETURN_MESSAGE").ToString();
                //rfcMessage.E_PO_NUMBER = rfc.GetInt("E_COUNT").ToString();
                //rfcMessage.E_EXPROC = rfc.GetInt("E_SUM").ToString();
                rfcMessage.E_MAT_DOC = rfc.GetString("E_MAT_DOC").ToString();
                return(rfcMessage);
            }
            catch (Exception exception)
            {
                rfcMessage.E_RETURN_MESSAGE = "接口STU 错误:" + exception.ToString();
                return(null);
            }
            finally
            {
                RfcDestinationManager.UnregisterDestinationConfiguration(_configurationId);
            }
        }
Exemplo n.º 14
0
        public DataTable  GetCargoLogisticoSAP(Int64 ObraId)
        {
            //var TD_TZONT = P.ReadTableDW("TZONT", '~', "LAND1,ZONE1,VTEXT", "LAND1 IN ('CO')", rfcDest, DefineDT.TZONT_DataBasic(), string.Empty, string.Empty);
            Dictionary <String, Object> response = null;
            DataTable DT = new DataTable();

            try
            {
                var config          = System.Configuration.ConfigurationManager.GetSection(ConfigurationName.Trim()) as NameValueCollection;
                var resultSeparator = config["ResultSeparator"].ToCharArray()[0];
                RfcDestinationManager.RegisterDestinationConfiguration(this.SAPConfig);
                RfcDestination rfcDest = RfcDestinationManager.GetDestination(this.ConfigurationName);
                RfcRepository  rfcRep  = null;
                rfcRep = rfcDest.Repository;
                IRfcFunction qry = rfcRep.CreateFunction("RFC_READ_TABLE");
                qry.SetValue("QUERY_TABLE", "KNVV");
                qry.SetValue("DELIMITER", resultSeparator);
                IRfcTable FIELDS = qry.GetTable("FIELDS");
                FIELDS.Append();
                FIELDS.SetValue("FIELDNAME", "ZZFUELSURC");
                FIELDS.Append();
                FIELDS.SetValue("FIELDNAME", "ZZDAMX33");
                IRfcTable OPTIONS = qry.GetTable("OPTIONS");
                OPTIONS.Append();
                OPTIONS.SetValue("TEXT", "KUNNR EQ '" + CompleteCodes(ObraId.ToString(), 10) + "' AND SPART EQ '03'");
                IRfcTable DATA = qry.GetTable("DATA");
                qry.Invoke(rfcDest);
                //DataTable DT = new DataTable();
                DT.Columns.Add("CargoCombustible");
                DT.Columns.Add("ZonaSuburbana");
                IRfcTable dataTable = qry.GetTable("DATA");
                string[]  columns;
                foreach (var dataRow in dataTable)
                {
                    string data = (string)dataRow.GetValue("WA");
                    columns = data.Split('|');
                    DT.LoadDataRow(columns.ToArray(), true);
                }
                return(DT);
            }

            catch (RfcLogonException le)
            {
                return(DT);
            }
            catch (Exception ex)
            {
                return(DT);
            }
            finally
            {
                RfcDestinationManager.UnregisterDestinationConfiguration(this.SAPConfig);
            }
            return(DT);
        }
Exemplo n.º 15
0
 public void DISConncet()
 {
     if (destination != null)
     {
         try
         {
             RfcDestinationManager.UnregisterDestinationConfiguration(ID);
         }
         catch { }
     }
 }
Exemplo n.º 16
0
        public RFC_OUT_Message Rfc_Fgu_Dal(List <RFC_FGU_Model.RFC_FGU_ITEM_Model> fguItemModel, RFC_FGU_Model.RFC_FGU_HEADER_Model fguHeaderModel)
        {
            RFC_OUT_Message rfcMessage = new RFC_OUT_Message();

            try
            {
                _configurationId = new RFC_SetUp();
                RfcDestinationManager.RegisterDestinationConfiguration(_configurationId);
                _dest       = RfcDestinationManager.GetDestination("SAPMS");
                _repository = _dest.Repository;
                IRfcFunction  rfc       = _repository.CreateFunction(fguHeaderModel.FunctionModule); //调用函数名
                IRfcTable     table     = rfc.GetTable(fguHeaderModel.E_SAP_FGU);                    //RFC表数据
                IRfcStructure structure = rfc.GetStructure("I_HEADER");                              //RFC表头数据
                structure.SetValue("ZMESKEY", fguHeaderModel.ZMESKEY);
                structure.SetValue("VBELN", fguHeaderModel.VBELN);
                structure.SetValue("WADAT_IST", fguHeaderModel.WADAT_IST);
                structure.SetValue("ZCOUNT", fguHeaderModel.ZCOUNT);
                structure.SetValue("ZSUM", fguHeaderModel.ZSUM);
                structure.SetValue("ZUSER", fguHeaderModel.ZUSER);
                structure.SetValue("ZSTEP", fguHeaderModel.ZSTEP);

                foreach (var _fguItemModel in fguItemModel)
                {
                    table.Insert();
                    table.CurrentRow.SetValue("ZMESITEM", _fguItemModel.ZMESITEM);
                    table.CurrentRow.SetValue("POSNR", _fguItemModel.POSNR);
                    table.CurrentRow.SetValue("MATNR", _fguItemModel.MATNR);
                    table.CurrentRow.SetValue("MENGE", _fguItemModel.MENGE);
                    table.CurrentRow.SetValue("MEINS", _fguItemModel.MEINS);
                    table.CurrentRow.SetValue("CHARG", _fguItemModel.CHARG);
                    table.CurrentRow.SetValue("ZLOTNO", _fguItemModel.ZLOTNO);
                    table.CurrentRow.SetValue("ZINBOXNO", _fguItemModel.ZINBOXNO);
                    table.CurrentRow.SetValue("LOTQTY", _fguItemModel.LOTQTY);
                    //fguHeaderModel.ZSUM += _fguItemModel.MENGE;//所有数据全部相加,取总数
                }
                structure.SetValue("ZSUM", fguHeaderModel.ZSUM);
                rfc.Invoke(_dest);
                rfcMessage.E_RETURN_CODE    = rfc.GetString("E_RETURN_CODE").ToString();
                rfcMessage.E_RETURN_MESSAGE = rfc.GetString("E_RETURN_MESSAGE").ToString();
                rfcMessage.E_MAT_DOC        = rfc.GetString("E_MAT_DOC").ToString();
                //rfcMessage.E_PO_NUMBER = rfc.GetInt("E_COUNT").ToString();
                //rfcMessage.E_EXPROC = rfc.GetInt("E_SUM").ToString();
                return(rfcMessage);
            }
            catch (Exception exception)
            {
                rfcMessage.E_RETURN_MESSAGE = "接口FGU 错误:" + exception.ToString();
                return(null);
            }
            finally
            {
                RfcDestinationManager.UnregisterDestinationConfiguration(_configurationId);
            }
        }
Exemplo n.º 17
0
        public static RfcDestination GetConnection(string DestinationName)
        {
            RfcDestination exists = null;

            //如果该连接已缓存,使用旧的

            if (_RFCs != null)
            {
                if (_RFCs.ContainsKey(DestinationName))
                {
                    exists = _RFCs[DestinationName];
                }
            }

            if (exists != null)
            {
                return(exists);
            }

            IDestinationConfiguration ID = new SaprouterConfig();

            try
            {
                RfcDestinationManager.RegisterDestinationConfiguration(ID);
            }
            catch (Exception ex)
            {
                WriteLog.WebGuiInLog("创建SAP连接失败:" + ex.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, "**********************");
            }

            exists = RfcDestinationManager.GetDestination(DestinationName);
            try
            {
                exists.Repository.ToString();
            }
            catch (Exception ex)
            {
                ex.ToString();
                (ID as SaprouterConfig).RemoveDestination(DestinationName);
            }

            try
            {
                RfcDestinationManager.UnregisterDestinationConfiguration(ID);
            }
            catch (Exception ex)
            {
                WriteLog.WebGuiInLog("注销SAP连接池失败:" + ex.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, "**********************");
            }

            //缓存本次新建连接
            _RFCs.Add(DestinationName, exists);
            return(exists);
        }
        public void KomisyonBedeliniGetir(string musteriNumarasi, DateTime?baslangicTarihi, DateTime?bitisTarihi
                                          , out DataTable dtITAB, out DataTable dtZRETURN)
        {
            SAPDestinationConfiguration sapDestinationConfiguration = new SAPDestinationConfiguration();

            IRfcFunction rfcFunction = null;

            try
            {
                // ishak.kulekci 24.06.2013
                //  Destination configuration already initialized hatasını engelleme, bunun için önce TryGetDestination kullanılır
                RfcDestination rfcDestination = RfcDestinationManager.TryGetDestination("SAPSYSTEM");
                if (rfcDestination == null)
                {
                    try
                    {
                        RfcDestinationManager.RegisterDestinationConfiguration(sapDestinationConfiguration);
                    }
                    catch (Exception ex)
                    {
                    }
                    rfcDestination = RfcDestinationManager.GetDestination("SAPSYSTEM");
                }

                //RfcDestination rfcDestination = RfcDestinationManager.GetDestination("SAPSYSTEM");
                rfcFunction = rfcDestination.Repository.CreateFunction("Z_RFC_YK_BEKPRIM_TO_INTERNET");
                //rfcFunction.SetValue("KUNNR", "100092"); // aygaz
                rfcFunction.SetValue("KUNNR", musteriNumarasi);
                //rfcFunction.SetValue("DATAB", "20130601");
                rfcFunction.SetValue("DATAB", baslangicTarihi.Value.ToString("yyyyMMdd", CultureInfo.GetCultureInfo("tr-tr")));
                //rfcFunction.SetValue("DATBI", "20130605");
                rfcFunction.SetValue("DATBI", bitisTarihi.Value.ToString("yyyyMMdd", CultureInfo.GetCultureInfo("tr-tr")));
                rfcFunction.Invoke(rfcDestination);
            }
            catch (Exception exception)
            {
                throw exception;
            }
            finally
            {
                try
                {
                    RfcDestinationManager.UnregisterDestinationConfiguration(sapDestinationConfiguration);
                }
                catch (Exception ex)
                {
                }
            }

            dtITAB    = RFCHelper.RfcTableToDataTable(rfcFunction.GetTable("ITAB"), "ITAB");
            dtZRETURN = RFCHelper.RfcTableToDataTable(rfcFunction.GetTable("ZRETURN"), "ZRETURN");
        }
Exemplo n.º 19
0
        public bool TestConnection()
        {
            bool result = false;


            SAPDestinationConfiguration sapDestinationConfiguration = new SAPDestinationConfiguration();


            try
            {
                // ishak.kulekci 24.06.2013
                //  Destination configuration already initialized hatasını engelleme, bunun için önce TryGetDestination kullanılır
                RfcDestination rfcDestination = RfcDestinationManager.TryGetDestination("SAPSYSTEM");
                if (rfcDestination == null)
                {
                    try
                    {
                        RfcDestinationManager.RegisterDestinationConfiguration(sapDestinationConfiguration);
                    }
                    catch (Exception ex)
                    {
                    }
                    rfcDestination = RfcDestinationManager.GetDestination("SAPSYSTEM");
                }

                if (rfcDestination != null)
                {
                    rfcDestination.Ping();
                    result = true;
                }
            }
            catch (Exception exception)
            {
                //throw exception;
                result = false;
                //throw new Exception("Connection failure error. Message:"+exception.Message);
            }
            finally
            {
                try
                {
                    RfcDestinationManager.UnregisterDestinationConfiguration(sapDestinationConfiguration);
                }
                catch (Exception ex)
                {
                }
            }

            return(result);
        }
Exemplo n.º 20
0
        public RFC_OUT_Message Rfc_Wtc_Dal(RFC_WTC_Model.RFC_WTC_HEADER_Model wtcHeaderModels)
        {
            RFC_OUT_Message rfcMessage = new RFC_OUT_Message();

            try
            {
                _configurationId = new RFC_SetUp();
                RfcDestinationManager.RegisterDestinationConfiguration(_configurationId);
                _dest       = RfcDestinationManager.GetDestination("SAPMS");
                _repository = _dest.Repository;
                IRfcFunction rfc = _repository.CreateFunction(wtcHeaderModels.FunctionModule); //调用函数名
                //RFC表数据
                IRfcStructure structure = rfc.GetStructure("I_HEADER");                        //RFC表头数据
                structure.SetValue("ZMESKEY", wtcHeaderModels.ZMESKEY);
                structure.SetValue("AUFNR", wtcHeaderModels.AUFNR);
                structure.SetValue("AUART", wtcHeaderModels.AUART);
                structure.SetValue("MATNR", wtcHeaderModels.MATNR);
                structure.SetValue("WERKS", wtcHeaderModels.WERKS);
                structure.SetValue("MENGE", wtcHeaderModels.MENGE);
                structure.SetValue("MEINS", wtcHeaderModels.MEINS);
                structure.SetValue("GLTRP", wtcHeaderModels.GLTRP);
                structure.SetValue("GSTRP", wtcHeaderModels.GSTRP);
                structure.SetValue("ZCOUNT", wtcHeaderModels.ZCOUNT);
                structure.SetValue("ZSUM", wtcHeaderModels.ZSUM);
                structure.SetValue("ZUSER", wtcHeaderModels.ZUSER);
                structure.SetValue("ZDELFLAG", wtcHeaderModels.ZDELFLAG);

                rfc.Invoke(_dest);
                rfcMessage.E_RETURN_CODE    = rfc.GetString("E_RETURN_CODE").ToString();
                rfcMessage.E_RETURN_MESSAGE = rfc.GetString("E_RETURN_MESSAGE").ToString();
                rfcMessage.E_PRD_ORD_NO     = rfc.GetString("E_PRD_ORD_NO").ToString();
                rfcMessage.E_EXPROC         = rfc.GetString("E_EXPROC").ToString();
                rfcMessage.E_PRD_CHARG      = rfc.GetString("E_PRD_CHARG").ToString();
                return(rfcMessage);
            }
            catch (Exception exception)
            {
                rfcMessage.E_RETURN_MESSAGE = "接口WTC 错误:" + exception.ToString();
                return(null);
            }
            finally
            {
                RfcDestinationManager.UnregisterDestinationConfiguration(_configurationId);
            }
        }
Exemplo n.º 21
0
        public RFC_OUT_Message Rfc_Fso_Dal(RFC_FSO_Model.RFC_FSO_HEADER_Model fsoHeaderModels)
        {
            RFC_OUT_Message rfcMessage = new RFC_OUT_Message();

            try
            {
                _configurationId = new RFC_SetUp();
                RfcDestinationManager.RegisterDestinationConfiguration(_configurationId);
                _dest       = RfcDestinationManager.GetDestination("SAPMS");
                _repository = _dest.Repository;
                IRfcFunction  rfc       = _repository.CreateFunction("Z_PP_MES_OUT_FSO"); //调用函数名
                IRfcStructure structure = rfc.GetStructure("I_HEADER");                   //RFC表头数据
                structure.SetValue("ZMESKEY", fsoHeaderModels.ZMESKEY);
                structure.SetValue("PLNUM", fsoHeaderModels.PLNUM);
                structure.SetValue("MATNR", fsoHeaderModels.MATNR);
                structure.SetValue("PWWRK", fsoHeaderModels.PWWRK);
                structure.SetValue("PLWRK", fsoHeaderModels.PLWRK);
                structure.SetValue("PAART", fsoHeaderModels.PAART);
                structure.SetValue("MENGE", fsoHeaderModels.MENGE);
                structure.SetValue("MEINS", fsoHeaderModels.MEINS);
                structure.SetValue("PSTTR", fsoHeaderModels.PSTTR);
                structure.SetValue("PEDTR", fsoHeaderModels.PEDTR);
                structure.SetValue("VERID", fsoHeaderModels.VERID);
                structure.SetValue("ZCOUNT", fsoHeaderModels.ZCOUNT);
                structure.SetValue("ZSUM", fsoHeaderModels.ZSUM);
                structure.SetValue("ZUSER", fsoHeaderModels.ZUSER);
                structure.SetValue("ZCLEARFLAG", fsoHeaderModels.ZCLEARFLAG);

                rfc.Invoke(_dest);
                rfcMessage.E_RETURN_CODE    = rfc.GetString("E_RETURN_CODE").ToString();
                rfcMessage.E_RETURN_MESSAGE = rfc.GetString("E_RETURN_MESSAGE").ToString();
                rfcMessage.E_PLAN_OR        = rfc.GetString("E_PLAN_OR").ToString();
                return(rfcMessage);
            }
            catch (Exception exception)
            {
                rfcMessage.E_RETURN_MESSAGE = "接口FSO 错误:" + exception.ToString();
                return(null);
            }
            finally
            {
                RfcDestinationManager.UnregisterDestinationConfiguration(_configurationId);
            }
        }
Exemplo n.º 22
0
        /*Exemplo de Envio para o SAP*/
        public string CriaOrdem(string ordem, string material, string dti, string dtf, string hri, string hrf, string qtd, string versao)
        {
            string detail;

            IRfcFunction companyBapi = repo.CreateFunction("Z_RFC_CRIA_OP");

            companyBapi.SetValue("ORDEM", ordem);
            companyBapi.SetValue("MATERIAL", material.PadRight(18, ' '));
            companyBapi.SetValue("START_DATE", Convert.ToDateTime(dti));
            companyBapi.SetValue("START_TIME", hri);
            companyBapi.SetValue("END_DATE", Convert.ToDateTime(dtf));
            companyBapi.SetValue("END_TIME", hrf);
            companyBapi.SetValue("QUANTITY", qtd);
            companyBapi.SetValue("PROD_VERSION", versao);

            companyBapi.Invoke(dest);
            detail = new string(companyBapi.GetCharArray("MENSAGEM"));

            RfcDestinationManager.UnregisterDestinationConfiguration(new SAPConnect());
            return(detail);
        }
Exemplo n.º 23
0
        public Boolean CreateConnection()
        {
            try
            {
                this.con = new SapConnection();
                RfcDestinationManager.RegisterDestinationConfiguration(con);
                this.dest = RfcDestinationManager.GetDestination("NSP");
                this.repo = dest.Repository;
            }
            catch (Exception ex)
            {
                try
                {
                    // Break connection
                    RfcDestinationManager.UnregisterDestinationConfiguration(con);
                }
                catch (Exception ex2) { }
                throw ex;
            }

            return(true);
        }
Exemplo n.º 24
0
        public IRfcTable Rfc_Goods_Dal(string I_FLAG, string I_RSNUM, string TABLES, out RFC_IN_Message rfcMessage)
        {
            rfcMessage = new RFC_IN_Message();
            try
            {
                _configurationId = new RFC_SetUp();
                RfcDestinationManager.RegisterDestinationConfiguration(_configurationId);
                _dest       = RfcDestinationManager.GetDestination("SAPMS");
                _repository = _dest.Repository;
                IRfcFunction rfc = _repository.CreateFunction("Z_MM_OPC_FG");   //调用函数名

                if (I_FLAG == "E")
                {
                    IRfcTable table = rfc.GetTable(TABLES);
                    rfc.SetValue("I_FLAG", "E");
                    rfc.Invoke(_dest);
                    return(table);
                }
                else
                {
                    IRfcTable table = rfc.GetTable(TABLES);
                    rfc.SetValue("I_RSNUM", I_RSNUM);
                    rfc.SetValue("I_FLAG", "B");
                    rfc.Invoke(_dest);
                    return(table);
                }
            }
            catch (Exception exception)
            {
                rfcMessage.E_RETURN_MESSAGE = "接口库存 错误:" + exception.ToString();
                return(null);
            }
            finally
            {
                RfcDestinationManager.UnregisterDestinationConfiguration(_configurationId);
            }
        }
Exemplo n.º 25
0
        public async Task <RespuestaMO> EnviarEstadoProcesoHostToHostAsync(CancellationToken cancelToken, String idSociedad, String anio, String momentoOrden, String idEstadoOrden, String idSap, String usuario, String tipoOrden)
        {
            RespuestaMO respuestaMO = null;

            try
            {
                DateTime?fecha = ConvertirCadenaHaciaFechaAsync(momentoOrden);
                RfcDestinationManager.RegisterDestinationConfiguration(_conexionSap);
                RfcConfigParameters rfcConfigParameters = GetParametersAsync();
                RfcDestination      rfcDestination      = RfcDestinationManager.GetDestination(rfcConfigParameters[RfcConfigParameters.Name]);
                RfcRepository       rfcRepository       = rfcDestination.Repository;
                IRfcFunction        rfcFunction         = rfcRepository.CreateFunction(Constante.FUNCTION_YFIRFC_ACTSTS_H2H);
                rfcFunction.SetValue(Constante.IP_BUKRS, idSociedad);
                rfcFunction.SetValue(Constante.IP_GJAHR, anio);
                rfcFunction.SetValue(Constante.IP_LAUFD, fecha);
                rfcFunction.SetValue(Constante.IP_BSTAT, idEstadoOrden);
                rfcFunction.SetValue(Constante.IP_REF1, idSap);
                rfcFunction.SetValue(Constante.IP_USNAM, usuario);
                rfcFunction.SetValue(Constante.IP_TIPO, tipoOrden);
                rfcFunction.Invoke(rfcDestination);
                IRfcStructure rfcStructureReturn = rfcFunction.GetStructure(Constante.EW_MENSG);
                respuestaMO = MapearEstructuraHaciaModeloAsync(rfcStructureReturn);
                String mensaje = respuestaMO.IdRespuesta == Constante.TYPE_SUCCESS ? Constante.MENSAJE_ENVIAR_ESTADO_PROCESO_HOSTTOHOST_ASYNC_OK : Constante.MENSAJE_ENVIAR_ESTADO_PROCESO_HOSTTOHOST_ASYNC_NO_OK;
                await _bitacora.RegistrarEventoAsync(cancelToken, Constante.BITACORA_NOTIFICACION, Constante.PROYECTO_NEGOCIO, Constante.CLASE_CONEXION_SAP_NE, Constante.METODO_ENVIAR_ESTADO_PROCESO_HOSTTOHOST_ASYNC, mensaje);
            }
            catch (Exception e)
            {
                await _bitacora.RegistrarEventoAsync(cancelToken, Constante.BITACORA_ERROR, Constante.PROYECTO_NEGOCIO, Constante.CLASE_CONEXION_SAP_NE, Constante.METODO_ENVIAR_ESTADO_PROCESO_HOSTTOHOST_ASYNC, Constante.MENSAJE_ENVIAR_ESTADO_PROCESO_HOSTTOHOST_ASYNC_NO_OK, e.Message);

                throw e;
            }
            finally
            {
                RfcDestinationManager.UnregisterDestinationConfiguration(_conexionSap);
            }
            return(respuestaMO);
        }
Exemplo n.º 26
0
        /// <summary>
        /// 取得供應商(藝術家)主檔
        /// </summary>
        /// <param name="P_DATE_from">異動日期起始,yyyyMMdd</param>
        /// <param name="P_DATE_TO">異動日期迄止,yyyyMMdd</param>
        /// <param name="P_NAME1">藝術家名</param>
        /// <returns></returns>
        public static List <ET_VENDOR> GetSap_Z_MM_ZHAW_CUBE2(string P_DATE_from, string P_DATE_TO, string P_NAME1)
        {
            IDestinationConfiguration ID = new MyBackendConfig();
            IRfcTable IRetTable          = null;

            bool             bRegistered   = false;
            List <ET_VENDOR> ET_VENDORList = new List <ET_VENDOR>();

            try
            {
                RfcDestination rfcDest = null;
                try
                {
                    rfcDest     = RfcDestinationManager.GetDestination("PRD");
                    bRegistered = true;
                }
                catch (Exception ex)
                {
                    if (ex.GetType().Name == "RfcInvalidStateException")
                    {
                    }
                }
                finally
                {
                    if (rfcDest == null && bRegistered == false)
                    {
                        bRegistered = true;
                        RfcDestinationManager.RegisterDestinationConfiguration(ID);
                        rfcDest = RfcDestinationManager.GetDestination("PRD");
                    }
                }
                RfcRepository rfcRepo = rfcDest.Repository;
                IRfcFunction  IReader = rfcRepo.CreateFunction("Z_MM_ZHAW_CUBE2");
                IReader.SetValue("P_DATE_from", P_DATE_from);
                IReader.SetValue("P_DATE_TO", P_DATE_TO);
                IReader.SetValue("P_NAME1", P_NAME1);
                //每幾筆資料切成一個檔案
                //IReader.SetValue("COUNT", "1000");
                //執行查詢
                IReader.Invoke(rfcDest);
                IRetTable = IReader.GetTable("ET_VENDOR");

                ET_VENDORList = IRetTable.AsEnumerable().Select(x =>
                                                                new ET_VENDOR()
                {
                    NAME1 = x.GetString("NAME1"),
                    LIFNR = x.GetString("LIFNR"),
                    SORTL = x.GetString("SORTL"),
                    LAND1 = x.GetString("LAND1"),
                    ERDAT = x.GetString("ERDAT"),
                    UDATE = x.GetString("UDATE") ?? ""
                }).ToList();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (bRegistered)
                {
                    RfcDestinationManager.UnregisterDestinationConfiguration(ID);
                }
            }

            return(ET_VENDORList);
        }
Exemplo n.º 27
0
        /// <summary>
        /// 取得商品(作品)主檔
        /// </summary>
        /// <param name="P_DATE_from">異動日期起始,yyyyMMdd</param>
        /// <param name="P_DATE_TO">異動日期迄止,yyyyMMdd</param>
        /// <param name="P_DESC">作品名</param>
        /// <param name="P_YEAR">年代,傳入格式%yyyy%yyyy%,兩個年份間,及前後加百分比</param>
        /// <param name="P_NAME1">作者名名</param>
        /// <returns></returns>
        public static List <ET_MASTER> GetSap_Z_MM_ZHAW_CUBE1(string P_DATE_from, string P_DATE_TO, string P_DESC = "", string P_YEAR = "", string P_NAME1 = "")
        {
            IDestinationConfiguration ID = new MyBackendConfig();
            IRfcTable IRetTable          = null;

            bool             bRegistered   = false;
            List <ET_MASTER> ET_MASTERList = new List <ET_MASTER>();

            try
            {
                RfcDestination rfcDest = null;
                try
                {
                    rfcDest     = RfcDestinationManager.GetDestination("PRD");
                    bRegistered = true;
                }
                catch (Exception ex)
                {
                    if (ex.GetType().Name == "RfcInvalidStateException")
                    {
                    }
                }
                finally
                {
                    if (rfcDest == null && bRegistered == false)
                    {
                        bRegistered = true;
                        RfcDestinationManager.RegisterDestinationConfiguration(ID);
                        rfcDest = RfcDestinationManager.GetDestination("PRD");
                    }
                }
                RfcRepository rfcRepo = rfcDest.Repository;
                IRfcFunction  IReader = rfcRepo.CreateFunction("Z_MM_ZHAW_CUBE1");
                IReader.SetValue("P_DATE_from", P_DATE_from);
                IReader.SetValue("P_DATE_TO", P_DATE_TO);
                IReader.SetValue("P_DESC", P_DESC);
                IReader.SetValue("P_YEAR", P_YEAR);
                IReader.SetValue("P_NAME1", P_NAME1);
                //每幾筆資料切成一個檔案
                //IReader.SetValue("COUNT", "1000");
                //執行查詢
                IReader.Invoke(rfcDest);
                IRetTable     = IReader.GetTable("ET_MASTER");
                ET_MASTERList = IRetTable.AsEnumerable().Select(x =>
                                                                new ET_MASTER()
                {
                    MATNR        = x.GetString("MATNR") ?? "",
                    ZZCT         = x.GetString("ZZCT") ?? "",
                    NAME1        = x.GetString("NAME1") ?? "",
                    ZFPRESERVE_D = x.GetString("ZFPRESERVE_D") ?? "",
                    ZZSE         = x.GetString("ZZSE") ?? "",
                    LOCATION     = x.GetString("LOCATION") ?? "",
                    STATUS       = x.GetString("STATUS") ?? "",
                    STPRS        = x.GetString("STPRS") ?? "",
                    NETPR        = x.GetString("NETPR") ?? "",
                    WAERS        = x.GetString("WAERS") ?? "",
                    ERDAT        = x.GetString("ERDAT") ?? "",
                    UDATE        = x.GetString("UDATE") ?? ""
                }).ToList();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (bRegistered)
                {
                    RfcDestinationManager.UnregisterDestinationConfiguration(ID);
                }
            }

            return(ET_MASTERList);
        }
Exemplo n.º 28
0
 public void Dispose()
 {
     RfcDestinationManager.UnregisterDestinationConfiguration(this.cfg);
 }
        public void LoadDataFromSAPERP(string[] newTP)
        {
            string werk   = "";
            string onDate = txbOnDate.Text;

            var settingsSP = (from s in context.SettingsSAPERPTbls
                              select s).FirstOrDefault();

            werk = settingsSP.Werk;

            if (werk == null || werk == "")
            {
                ErrorLabel1.Text        = "Не указан в настройках завод магазина";
                Wizard1.ActiveStepIndex = 1;
                return;
            }

            MyBackendConfig2 cfg = new MyBackendConfig2();

            try
            {
                // delete all
                var sap1Del = from p in context.SAPOUT_REST
                              select p;
                context.SAPOUT_REST.DeleteAllOnSubmit(sap1Del);
                context.SubmitChanges();
                var sap2Del = from p in context.SAPOUT_SMENA
                              select p;
                context.SAPOUT_SMENA.DeleteAllOnSubmit(sap2Del);
                context.SubmitChanges();
                //-----------------------------

                RfcDestinationManager.RegisterDestinationConfiguration(cfg);      //1
                RfcDestination prd = RfcDestinationManager.GetDestination("AEP"); //2


                RfcRepository repo = prd.Repository;//3

                IRfcFunction pricesBapi =
                    repo.CreateFunction("Y_GET_MATNR_REST"); //4
                pricesBapi.SetValue("I_WERKS", werk);        //5
                //pricesBapi.SetValue("I_DATE", onDate); //5

                IRfcTable detail1 = pricesBapi.GetTable("TAB");

                foreach (string strs in newTP)
                {
                    detail1.Append();

                    detail1.SetValue("MATNR", strs);
                    detail1.SetValue("MAKTX", "");
                    detail1.SetValue("LGORT", "");
                    detail1.SetValue("LABST", 0.0);
                    detail1.SetValue("MEINS", "");
                }

                pricesBapi.Invoke(prd); //6
                IRfcTable detail3 = pricesBapi.GetTable("TAB");


                DateTime tsmp = DateTime.Now;

                int i = 0;
                foreach (IRfcStructure elem in detail3)
                {
                    string matnr = elem[0].GetString();
                    string maktx = elem[1].GetString();
                    string lgort = elem[2].GetString();
                    double labst = elem[3].GetDouble();
                    string meins = elem[4].GetString();

                    SAPOUT_REST np = new SAPOUT_REST();
                    np.MATNR     = matnr;
                    np.MAKTX     = maktx;
                    np.LGORT     = lgort;
                    np.LABST     = labst;
                    np.MEINS     = meins;
                    np.TimeStamp = tsmp;
                    context.SAPOUT_REST.InsertOnSubmit(np);

                    if (i == 100)
                    {
                        context.SubmitChanges();
                        i = 0;
                    }
                    i++;
                }
                context.SubmitChanges();



                RfcRepository repo2 = prd.Repository;//3

                IRfcFunction pricesBapi2 =
                    repo2.CreateFunction("Y_GET_SMENA"); //4
                pricesBapi2.SetValue("I_WERKS", werk);   //5
                pricesBapi2.SetValue("I_DATE", onDate);  //5
                pricesBapi2.Invoke(prd);                 //6
                IRfcTable detail2 = pricesBapi2.GetTable("TAB");

                tsmp = DateTime.Now;

                i = 0;
                foreach (IRfcStructure elem in detail2)
                {
                    string sm_date = elem[0].GetString();
                    string smena   = elem[1].GetString();

                    SAPOUT_SMENA np = new SAPOUT_SMENA();
                    np.SM_DATE   = DateTime.Parse(sm_date);
                    np.SMENA     = smena;
                    np.TimeStamp = tsmp;
                    context.SAPOUT_SMENA.InsertOnSubmit(np);

                    if (i == 100)
                    {
                        context.SubmitChanges();
                        i = 0;
                    }
                    i++;
                }
                context.SubmitChanges();



                //String companyName = detail.
                //    GetString("NAME1");//7
                //Console.WriteLine(companyName);
                //Console.Read();
            }
            catch (RfcInvalidStateException e)
            {
                // cascade up callstack
                ErrorLabel1.Text        = "Проблема повторного подключения к SAP: " + e.Message;
                Wizard1.ActiveStepIndex = 1;

                Log l = new Log();
                l.Message   = e.Message;
                l.Type      = "SAP";
                l.TimeStamp = DateTime.Now;
                context.Logs.InsertOnSubmit(l);
                context.SubmitChanges();
            }
            catch (RfcCommunicationException e)
            {
                // network problem...
                ErrorLabel1.Text        = "Сетевая проблема подключения к SAP: " + e.Message;
                Wizard1.ActiveStepIndex = 1;

                Log l = new Log();
                l.Message   = e.Message;
                l.Type      = "SAP";
                l.TimeStamp = DateTime.Now;
                context.Logs.InsertOnSubmit(l);
                context.SubmitChanges();
            }
            catch (RfcLogonException e)
            {
                // user could not logon...
                ErrorLabel1.Text        = "Не правильный пользователь для подключения к SAP: " + e.Message;
                Wizard1.ActiveStepIndex = 1;

                Log l = new Log();
                l.Message   = e.Message;
                l.Type      = "SAP";
                l.TimeStamp = DateTime.Now;
                context.Logs.InsertOnSubmit(l);
                context.SubmitChanges();
            }
            catch (RfcAbapRuntimeException e)
            {
                // serious problem on ABAP system side...
                ErrorLabel1.Text        = "Серьезная проблема на стороне SAP обратитесь в службу поддержки SAP (serious problem on ABAP system side...): " + e.Message;
                Wizard1.ActiveStepIndex = 1;

                Log l = new Log();
                l.Message   = e.Message;
                l.Type      = "SAP";
                l.TimeStamp = DateTime.Now;
                context.Logs.InsertOnSubmit(l);
                context.SubmitChanges();
            }
            catch (RfcAbapBaseException e)
            {
                // The function module returned an ABAP exception, an ABAP message
                // or an ABAP class-based exception...
                ErrorLabel1.Text        = "Серьезная проблема на стороне SAP обратитесь в службу поддержки SAP (The function module returned an ABAP exception, an ABAP message): " + e.Message;
                Wizard1.ActiveStepIndex = 1;

                Log l = new Log();
                l.Message   = e.Message;
                l.Type      = "SAP";
                l.TimeStamp = DateTime.Now;
                context.Logs.InsertOnSubmit(l);
                context.SubmitChanges();
            }
            finally
            {
                RfcDestinationManager.UnregisterDestinationConfiguration(cfg);//1
            }
        }
Exemplo n.º 30
0
 public static void TearDown()
 {
     // unregister the in-memory destination configuration -- called after we are done working with the examples
     RfcDestinationManager.UnregisterDestinationConfiguration(inMemoryDestinationConfiguration);
 }