コード例 #1
0
        public InvoiceValueModel GetInvoiceValue(RfcDestination rfcDest)
        {
            InvoiceValueModel invoiceValueModel = new InvoiceValueModel();
            RfcDestination    SAPRfcDestination = RfcDestinationManager.GetDestination("accelyides");

            RfcRepository rfcrep = SAPRfcDestination.Repository;
            IRfcFunction  BapiGetCompanyDetail = null;


            BapiGetCompanyDetail = rfcrep.CreateFunction("BAPI_INCOMINGINVOICE_GETDETAIL");
            BapiGetCompanyDetail.SetValue("INVOICEDOCNUMBER", "1000000020");
            BapiGetCompanyDetail.SetValue("FISCALYEAR", "2013");
            BapiGetCompanyDetail.Invoke(rfcDest);
            IRfcTable tblReturn = BapiGetCompanyDetail.GetTable("ITEMDATA");
            DataTable TBL       = tblReturn.ToDataTable("TBL");

            for (int i = 0; i < TBL.Rows.Count; i++)
            {
                InvoiceValueModel invoiceValueModel1 = new InvoiceValueModel();

                invoiceValueModel1.REF_DOC = TBL.Rows[i]["REF_DOC"].ToString();
                // invoiceValueModel.lstInvoiceValue.Add(invoiceValueModel1);
            }

            IRfcStructure IRS_OS_HEADER = BapiGetCompanyDetail.GetStructure("HEADERDATA");

            invoiceValueModel.Value = IRS_OS_HEADER.GetValue("USERNAME").ToString();
            //Console.WriteLine(invoiceValueModel.Value);
            //Console.ReadKey();
            RfcSessionManager.EndContext(rfcDest);

            return(invoiceValueModel);
        }
コード例 #2
0
 public static void closeContextIfNeeded(HttpContext currentContext, String sapClientName, RfcDestination destination)
 {
     if (!isManualContext(currentContext, sapClientName) && !isStatelessRegion(currentContext, sapClientName))
     {
         RfcSessionManager.EndContext(destination);
     }
 }
コード例 #3
0
ファイル: SAPRFC.cs プロジェクト: chittasn/SpoWebApi
        /// <summary>
        ///  To get the list of Products
        /// </summary>
        ///
        public List <SIISAPProdDTO> GetProducts()
        {
            List <SIISAPProdDTO> objProdutsList = new List <SIISAPProdDTO>();
            var rfcDestination = RfcDestinationManager.GetDestination("SIISAP");

            try
            {
                if (rfcDestination != null)
                {
                    var getARNRfc = rfcDestination.Repository.CreateFunction("ZEHS_MSDS_PRTL_F4_PROD");
                    RfcSessionManager.BeginContext(rfcDestination);
                    getARNRfc.Invoke(rfcDestination);
                    var GetProductsTable = getARNRfc.GetTable("PRODS");



                    foreach (var row in GetProductsTable)
                    {
                        objProdutsList.Add(new SIISAPProdDTO {
                            Product = row[0].ToString().Substring(row[0].ToString().IndexOf("=") + 1)
                        });
                        var listinfo = objProdutsList;
                    }
                    RfcSessionManager.EndContext(rfcDestination);
                    rfcDestination = null;
                }
            }
            catch (Exception ex)
            {
                FilePath = ConfigurationManager.AppSettings["siteUrl"];
                WriteLog(FilePath, ex.Message);
            }

            return(objProdutsList);
        }
コード例 #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            rfc_Connector cfg = null;

            cfg = new rfc_Connector();

            IRfcFunction getDataSAP = GlobalData.rfcRepository.CreateFunction("ZPM_ORDER_01_CONFIRM");

            IRfcTable IT_DATA = getDataSAP.GetTable("LT_ORDER_CONF");

            IT_DATA.Clear();
            IT_DATA.Append();
            IT_DATA.SetValue("AUFNR", aufnr.Text);
            IT_DATA.SetValue("VORNR", vornr.Text);
            if (ck1.Checked == true)
            {
                IT_DATA.SetValue("AUERU", "X");
            }

            try
            {
                getDataSAP.Invoke(GlobalData.rfcDestination);
                RfcSessionManager.EndContext(GlobalData.rfcDestination);

                //var exObject = getDataSAP.GetObject("MESSAGE");
                MessageBox.Show("Order Confirmed");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #5
0
        /// <summary>
        /// 物料凭证查询
        /// </summary>
        /// <param name="I_BKTXT">凭证抬头文本(凭证号与抬头文本至少填一个)</param>
        /// <param name="I_MBLNR">物料凭证(凭证号与抬头文本至少填一个)</param>
        /// <param name="I_MJAHR">物料凭证年度(选填)</param>
        /// <returns></returns>
        public static Result ZWMS_MKPF(string I_BKTXT, string I_MBLNR = "", string I_MJAHR = "")
        {
            Result result = new Result {
                Success = false
            };

            try
            {
                //RfcDestination rfcDest = RfcDestinationManager.GetDestination(GetSapServerString());
                RfcDestination rfcDest = RfcDestinationManager.GetDestination(ConfigurationManager.AppSettings["sapServer"].ToString());

                //选择要调用的BAPI的名称
                RfcFunctionMetadata rfMD = rfcDest.Repository.GetFunctionMetadata("ZWMS_MKPF");
                //新建调用该BAPI的一个“实例”
                IRfcFunction irF = rfMD.CreateFunction();

                //******************************
                //输入参数设置
                //******************************

                irF.SetValue("I_MBLNR", I_MBLNR);   //物料凭证
                irF.SetValue("I_MJAHR", I_MJAHR);   //物料凭证年度
                irF.SetValue("I_BKTXT", I_BKTXT);   //凭证抬头文本

                IRfcTable irt = irF.GetTable("O_MKPF");

                RfcSessionManager.BeginContext(rfcDest);

                irF.Invoke(rfcDest);
                //irfCommit.Invoke(rfcDest);

                RfcSessionManager.EndContext(rfcDest);

                result.Success = irF.GetString("RTYPE").ToUpper() == "S";
                result.Message = irF.GetValue("RTMSG").ToString();
                if (result.Success && irt.RowCount > 0)
                {
                    var MBLNR = "";
                    for (int i = 0; i < irt.RowCount; i++)
                    {
                        irt.CurrentIndex = i;
                        if (MBLNR.IsNotEmpty())
                        {
                            MBLNR += "/";
                        }
                        MBLNR += irt.GetString("MBLNR");
                    }
                    result.Message = MBLNR;
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
            }
            return(result);
        }
コード例 #6
0
 private SapConnection()
 {
     m_liveSessions = new Dictionary <string, Thread>();
     m_session      = new SapSessionProvider();
     if (!RfcSessionManager.IsSessionProviderRegistered())
     {
         RfcSessionManager.RegisterSessionProvider(m_session);
     }
 }
コード例 #7
0
        /// <summary>
        /// Start a new Session/Context.
        /// </summary>
        public void StartSession()
        {
            if (SessionProvider != null)
            {
                RfcSessionManager.RegisterSessionProvider(SessionProvider);
            }

            RfcSessionManager.BeginContext(_connection.Destination);
        }
コード例 #8
0
        /// <summary>
        /// End the current Session/Context.
        /// </summary>
        public void EndSession()
        {
            if (SessionProvider != null)
            {
                RfcSessionManager.UnregisterSessionProvider(SessionProvider);
                SessionProvider = null;
            }

            RfcSessionManager.EndContext(_connection.Destination);
        }
コード例 #9
0
ファイル: UTL.cs プロジェクト: pfs-haibv/projpscd
        // Kiểm tra dữ liệu tờ khai 10/KK-TNCN
        public static string Prc_check_data_tk10(string p_short_name, string p_tax_code, DataRow p_dr, RfcDestination p_sap, string p_ky_chot_dl)
        {
            // Bắt đầu một session
            RfcSessionManager.BeginContext(p_sap);
            RfcRepository v_repo  = p_sap.Repository;
            IRfcFunction  v_babi  = v_repo.CreateFunction("ZBAPI_DETAIL_10_CHECK");
            IRfcStructure v_struc = v_babi.GetStructure("I_DATA");

            v_struc.SetValue("TAXPAYER_ID", p_dr["TIN"].ToString());
            v_struc.SetValue("START_PERIOD", p_dr["KYKK_TU_NGAY"].ToString());
            v_struc.SetValue("END_PERIOD", p_dr["KYKK_DEN_NGAY"].ToString());
            v_struc.SetValue("DUE_DATE", p_dr["KYLB_TU_NGAY"].ToString());
            v_struc.SetValue("A_F08_DOANH_THU_DU_KIEN", p_dr["DTHU_DKIEN"].ToString());
            v_struc.SetValue("A_F09_TY_LE_TNCT_DU_KIEN", p_dr["TL_THNHAP_DKIEN"].ToString());
            v_struc.SetValue("C_F10_TNCT_DU_KIEN", p_dr["THNHAP_CTHUE_DKIEN"].ToString());
            v_struc.SetValue("C_F11_GIAM_TRU_GC", p_dr["GTRU_GCANH"].ToString());
            v_struc.SetValue("A_F12_GIAM_TRU_BAN_THAN", p_dr["BAN_THAN"].ToString());
            v_struc.SetValue("A_F13_GIAM_TRU_NPT", p_dr["PHU_THUOC"].ToString());
            v_struc.SetValue("C_F14_THU_NHAP_TINH_THUE", p_dr["THNHAP_TTHUE_DKIEN"].ToString());
            v_struc.SetValue("C_F15_THUE_TNCN_DU_KIEN", p_dr["TNCN"].ToString());
            v_struc.SetValue("C_F16_THUE_PN_Q1", p_dr["PB01"].ToString());
            v_struc.SetValue("C_F16_KY_TINH_THUE_Q1", p_dr["KYTT01"].ToString());
            v_struc.SetValue("C_F16_KY_HACH_TOAN_Q1", p_dr["HT01"].ToString());
            v_struc.SetValue("C_F16_HAN_NOP_Q1", p_dr["HN01"].ToString());
            v_struc.SetValue("C_F17_THUE_PN_Q2", p_dr["PB02"].ToString());
            v_struc.SetValue("C_F17_KY_TINH_THUE_Q2", p_dr["KYTT02"].ToString());
            v_struc.SetValue("C_F17_KY_HACH_TOAN_Q2", p_dr["HT02"].ToString());
            v_struc.SetValue("C_F17_HAN_NOP_Q2", p_dr["HN02"].ToString());
            v_struc.SetValue("C_F18_THUE_PN_Q3", p_dr["PB03"].ToString());
            v_struc.SetValue("C_F18_KY_TINH_THUE_Q3", p_dr["KYTT03"].ToString());
            v_struc.SetValue("C_F18_KY_HACH_TOAN_Q3", p_dr["HT03"].ToString());
            v_struc.SetValue("C_F18_HAN_NOP_Q3", p_dr["HN03"].ToString());
            v_struc.SetValue("C_F19_THUE_PN_Q4", p_dr["PB04"].ToString());
            v_struc.SetValue("C_F19_KY_TINH_THUE_Q4", p_dr["KYTT04"].ToString());
            v_struc.SetValue("C_F19_KY_HACH_TOAN_Q4", p_dr["HT04"].ToString());
            v_struc.SetValue("C_F19_HAN_NOP_Q4", p_dr["HN04"].ToString());
            v_struc.SetValue("TAX_OFFICE_CODE", p_dr["MA_CQT"].ToString());
            v_struc.SetValue("ROW_NUM", p_dr["STT"].ToString());
            v_struc.SetValue("F13_MST_DLT", p_dr["MST_DTK"].ToString());
            v_struc.SetValue("F20_HOP_DONG_DLT_SO", p_dr["HD_DLT_SO"].ToString());
            v_struc.SetValue("F_HOP_DONG_DLT_NGAY", p_dr["HD_DLT_NGAY"].ToString());
            v_struc.SetValue("REVERSE_AMOUNT", p_dr["RV_SO_TIEN"].ToString());

            v_babi.SetValue("I_FILE", randomFileName(p_tax_code, p_ky_chot_dl));

            v_babi.Invoke(p_sap);
            // Kết thúc một session
            RfcSessionManager.EndContext(p_sap);
            return(v_babi.GetString("E_ERROR_CODE"));
        }
コード例 #10
0
        private void button1_Click(object sender, EventArgs e)
        {
            string dateStr = "";
            string timeStr = "";

            dateStr = dtDate.Text.Substring(6, 4) + "" + dtDate.Text.Substring(3, 2) + "" + dtDate.Text.Substring(0, 2);
            timeStr = dtTime.Text.Substring(0, 2) + "" + dtTime.Text.Substring(3, 2) + "" + dtTime.Text.Substring(6, 2);

            rfc_Connector cfg = null;

            cfg = new rfc_Connector();

            IRfcFunction getDataSAP = GlobalData.rfcRepository.CreateFunction("ZPM_NOTIF_01");

            IRfcStructure ls_ticketdata = getDataSAP.GetStructure("TICKED_DATA");
            IRfcStructure ls_result     = getDataSAP.GetStructure("RESULT");

            ls_ticketdata.SetValue("EQFNR", txt01.Text);
            ls_ticketdata.SetValue("QMART", cb01.Text);
            ls_ticketdata.SetValue("QMTXT", txt02.Text);
            ls_ticketdata.SetValue("TPLNR", txt03.Text);
            ls_ticketdata.SetValue("EQUNR", txt04.Text);
            ls_ticketdata.SetValue("QMNAM", txt05.Text);
            ls_ticketdata.SetValue("QMDAT", dateStr);
            ls_ticketdata.SetValue("MZEIT", timeStr);

            ls_ticketdata.SetValue("PRIOK", cbPriok.Text);
            ls_ticketdata.SetValue("STRMN", dateStr);
            ls_ticketdata.SetValue("LTRMN", dateStr);
            ls_ticketdata.SetValue("STRUR", timeStr);
            ls_ticketdata.SetValue("LTRUR", timeStr);

            ls_ticketdata.SetValue("ZBEBER", txt06.Text);
            ls_ticketdata.SetValue("ZBEBER2", txt07.Text);
            ls_ticketdata.SetValue("ZTPLNR2", txt08.Text);
            ls_ticketdata.SetValue("ZKOSTL", txt09.Text);

            try
            {
                getDataSAP.Invoke(GlobalData.rfcDestination);
                RfcSessionManager.EndContext(GlobalData.rfcDestination);

                IRfcStructure exStructure = getDataSAP.GetStructure("RESULT");
                MessageBox.Show(exStructure.GetValue("MESSAGE") + " - " + exStructure.GetValue("DOCNUM"));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #11
0
ファイル: SAPVendor.cs プロジェクト: Rashmi-Salaria/Finocart
        /// <summary>
        /// Getting vendor details from SAP
        /// Date: 20 June 2019
        /// Developer: Shreyans Khandelwal (0538)
        /// </summary>
        /// <param name="rfcDest"></param>
        /// <returns></returns>
        public VendorDetail GetVendorDetail(RfcDestination rfcDest)
        {
            try
            {
                VendorDetail vendorDetModel = new VendorDetail();

                RfcDestination SAPRfcDestination = RfcDestinationManager.GetDestination("accelyides");

                RfcRepository rfcrep = SAPRfcDestination.Repository;
                IRfcFunction  BapiGetCompanyDetail = null;


                BapiGetCompanyDetail = rfcrep.CreateFunction("BAPI_VENDOR_GETDETAIL");
                BapiGetCompanyDetail.SetValue("VENDORNO", "VBX");
                BapiGetCompanyDetail.SetValue("COMPANYCODE", "0001");
                BapiGetCompanyDetail.Invoke(rfcDest);

                IRfcStructure IRS_OS_GeneralDet = BapiGetCompanyDetail.GetStructure("GENERALDETAIL");
                vendorDetModel.CompanyName   = IRS_OS_GeneralDet.GetValue("VENDOR").ToString();
                vendorDetModel.ContactName   = IRS_OS_GeneralDet.GetValue("NAME").ToString();
                vendorDetModel.ContactMobile = IRS_OS_GeneralDet.GetValue("TELEPHONE").ToString();
                vendorDetModel.Address       = IRS_OS_GeneralDet.GetValue("FORMOFADDR").ToString();
                //vendorDetModel.NAME_2 = IRS_OS_GeneralDet.GetValue("NAME_2").ToString();
                //vendorDetModel.NAME_3 = IRS_OS_GeneralDet.GetValue("NAME_3").ToString();
                //vendorDetModel.NAME_4 = IRS_OS_GeneralDet.GetValue("NAME_4").ToString();
                //vendorDetModel.CITY = IRS_OS_GeneralDet.GetValue("CITY").ToString();
                //vendorDetModel.DISTRICT = IRS_OS_GeneralDet.GetValue("DISTRICT").ToString();
                //vendorDetModel.PO_BOX = IRS_OS_GeneralDet.GetValue("PO_BOX").ToString();
                //vendorDetModel.POBX_PCD = IRS_OS_GeneralDet.GetValue("POBX_PCD").ToString();
                //vendorDetModel.POSTL_CODE = IRS_OS_GeneralDet.GetValue("POSTL_CODE").ToString();
                //vendorDetModel.REGION = IRS_OS_GeneralDet.GetValue("REGION").ToString();
                ////vendorDetModel.Address = IRS_OS_GeneralDet.GetValue("STREET").ToString();
                //vendorDetModel.COUNTRY = IRS_OS_GeneralDet.GetValue("STREET").ToString();
                //vendorDetModel.COUNTRYISO = IRS_OS_GeneralDet.GetValue("COUNTRYISO").ToString();
                //vendorDetModel.POBX_CTY = IRS_OS_GeneralDet.GetValue("POBX_CTY").ToString();
                //vendorDetModel.LANGU = IRS_OS_GeneralDet.GetValue("LANGU").ToString();
                //vendorDetModel.LANGU_ISO = IRS_OS_GeneralDet.GetValue("LANGU_ISO").ToString();
                //vendorDetModel.TELEPHONE2 = IRS_OS_GeneralDet.GetValue("TELEPHONE2").ToString();

                RfcSessionManager.EndContext(rfcDest);

                return(vendorDetModel);
            }
            catch (Exception ex)
            {
                logger.WriteLog(ex);
                throw ex;
            }
        }
コード例 #12
0
        public static string CheckSAPConnection()
        {
            Innovator innovator = IomFactory.CreateInnovator(connection);
            string    result;

            Item queryPart = innovator.newItem("GAG_SAPInterfaceSettings", "get");

            queryPart.setProperty("gag_active", "Yes");
            Item queryResult = queryPart.apply();

            if (queryResult.isEmpty())
            {
                result = "No SAP Connection Found. Contact Admin";
                return(result);
            }
            try
            {
                Item sapResult = queryResult.getItemByIndex(0);
                RfcConfigParameters parameters = new RfcConfigParameters
                {
                    [RfcConfigParameters.Name]                  = sapResult.getProperty("gag_name"),
                    [RfcConfigParameters.User]                  = ConfigurationManager.AppSettings.Get("userSAP"),
                    [RfcConfigParameters.Password]              = ConfigurationManager.AppSettings.Get("passwordSAP"),
                    [RfcConfigParameters.PeakConnectionsLimit]  = sapResult.getProperty("gag_peak_connection_limit"),
                    [RfcConfigParameters.ConnectionIdleTimeout] = sapResult.getProperty("gag_connection_idle_time_out"),
                    [RfcConfigParameters.Language]              = sapResult.getProperty("gag_language"),
                    [RfcConfigParameters.AppServerHost]         = sapResult.getProperty("gag_app_server_host"),
                    [RfcConfigParameters.SystemNumber]          = sapResult.getProperty("gag_system_number"),
                    [RfcConfigParameters.Client]                = sapResult.getProperty("gag_client")
                };
                destination = RfcDestinationManager.GetDestination(parameters);
                RfcSessionManager.BeginContext(destination);
                destination.Ping();

                result = "Connection Successful";
                return(result);
            }
            catch (RfcLogonException)
            {
                result = "SAP Log-In Failed";
                return(result);
            }
            catch (RfcCommunicationException)
            {
                result = "SAP Server Connection Error";
                return(result);
            }
        }
コード例 #13
0
        public FunctionResult ExecuteInsert(string functionName, List <NTable> parameters, List <string> tableNames)
        {
            try
            {
                _function = _destination.Repository.CreateFunction(functionName);

                for (int i = 0; i < tableNames.Count; i++)
                {
                    RfcStructureMetadata metaData = _destination.Repository.GetStructureMetadata(parameters[i].StructureName);

                    IRfcTable tblInput = _function.GetTable(tableNames[i]);

                    foreach (DataRow row in parameters[i].Parameters.Rows)
                    {
                        IRfcStructure structRow = metaData.CreateStructure();

                        foreach (DataColumn column in parameters[i].Parameters.Columns)
                        {
                            object obj = row[column];
                            structRow.SetValue(column.ToString(), obj);
                        }

                        tblInput.Append(structRow);
                    }
                }

                RfcSessionManager.BeginContext(_destination);
                _function.Invoke(_destination);

                IRfcTable returnTable = _function.GetTable("NOTESRETURN");

                return(new FunctionResult
                {
                    IsSuccess = true,
                    Data = new List <object> {
                        returnTable
                    }
                });
            }
            catch (Exception ex)
            {
                return(new FunctionResult
                {
                    IsSuccess = false,
                    ErrorMessage = ex.ToString()
                });
            }
        }
コード例 #14
0
ファイル: SAPRFC.cs プロジェクト: chittasn/SpoWebApi
        /// <summary>
        ///
        /// </summary>
        /// <param name="MaterialNo"></param>
        /// <param name="ProductName"></param>
        /// <returns></returns>
        public string RTFtoPDFFile(string MaterialNo, string ProductName, string strRegion, string strLanguageName, string strVersion, string rtfFileName)
        {
            var    rfcRTFtoPDFFile = RfcDestinationManager.GetDestination("SIISAP");
            string filePath        = string.Empty;
            string strFilePathURL  = string.Empty;
            var    GetFile         = string.Empty;

            try
            {
                if (rfcRTFtoPDFFile != null)
                {
                    var getGateEntryRfc = rfcRTFtoPDFFile.Repository.CreateFunction("ZEHS_MSDS_PRTL_TRAN_RTF_FILE");
                    /// PRODUCT
                    getGateEntryRfc.SetValue("I_RECN", MaterialNo);    // 10415919);
                    getGateEntryRfc.SetValue("I_BRAND2", ProductName); // "ALKANOX® 240");
                    getGateEntryRfc.Invoke(rfcRTFtoPDFFile);
                    GetFile = getGateEntryRfc.GetValue("E_FILE").ToString();
                    IRfcTable tblValueFile      = getGateEntryRfc.GetTable("E_VALUEFILE_TAB");
                    IRfcTable ObjectRTFDocument = getGateEntryRfc.GetTable("E_DOCUMENT_TAB");
                    RfcSessionManager.EndContext(rfcRTFtoPDFFile);
                    var SiteUrl       = ConfigurationManager.AppSettings["siteUrl"];
                    var fileDirectory = ConfigurationManager.AppSettings["fileDirectory"] + GetFile;
                    var libraryName   = ConfigurationManager.AppSettings["strlibraryName"];

                    var strDestinationPath = string.Empty;

                    string strFileForMaterialNo = rtfFileName.Replace(" ", "_");
                    strDestinationPath = HttpContext.Current.Server.MapPath("~/SharePoint") + "\\" + strFileForMaterialNo.Replace("/", "_") + "_" + strRegion + "_" + strLanguageName + "_" + strVersion + ".rtf";

                    //// Below function "DownloadFileByte" to download file from shared location and convert them bytes.
                    byte[] readFile = DownloadFileByte(fileDirectory);

                    ////Below function to "SaveBytesToFile" to convert the bytes to file with product name
                    string strfielName = SaveBytesToFile(strDestinationPath, readFile);
                    strFilePathURL = strfielName;

                    rfcRTFtoPDFFile = null;
                }
            }
            catch (Exception ex)
            {
                RfcSessionManager.EndContext(rfcRTFtoPDFFile);
                rfcRTFtoPDFFile = null;
                FilePath        = ConfigurationManager.AppSettings["ErrorFilePath"];
                WriteLog(FilePath, ex.Message);
            }
            return(strFilePathURL);
        }
コード例 #15
0
        public static void initializeContext(HttpContext currentContext, String sapClientName, RfcDestination destination)
        {
            bool manualContext = isManualContext(currentContext, sapClientName);

            if (manualContext)
            {
                var manualContexts = (Dictionary <String, RfcDestination>)currentContext.Items[SapManualContextsKey];
                if (!manualContexts.ContainsKey(sapClientName) || manualContexts[sapClientName] == null)
                {
                    manualContexts[sapClientName] = destination;
                    RfcSessionManager.BeginContext(destination);
                }
            }
            else if (!isStatelessRegion(currentContext, sapClientName))
            {
                RfcSessionManager.BeginContext(destination);
            }
        }
コード例 #16
0
        public void Dispose()
        {
            if (SessionProvider == null)
            {
                return;
            }

            try
            {
                RfcSessionManager.UnregisterSessionProvider(SessionProvider);
            }
            catch (Exception ex)
            {
                Trace.TraceError("An error occurred when trying to unregister sessionProvider of type '{0}'.Exception: {1}", SessionProvider.GetType().Name, ex.ToString());
            }

            GC.SuppressFinalize(this);
        }
コード例 #17
0
        /// <summary>
        /// Ends a manually controlled context.
        /// </summary>
        /// <param name="connectionName">The name of the SAP connection which context is to be terminated.</param>
        public static void EndContext(String connectionName)
        {
            Dictionary <String, RfcDestination> SapManualContexts = GetSapManualContexts();

            if (SapManualContexts != null)
            {
                RfcDestination destination = SapManualContexts[connectionName];
                if (destination != null)
                {
                    RfcSessionManager.EndContext(destination);
                }
                else
                {
                    throw new Exception("Unable to access the remote destination on connection: " + connectionName);
                }
                SapManualContexts.Remove(connectionName);
                return;
            }
            throw new Exception("No manually controlled context found for the connection: " + connectionName);
        }
コード例 #18
0
ファイル: Form1.cs プロジェクト: HusnulM/sap-rfc-csharp
        private void button2_Click(object sender, EventArgs e)
        {
            rfc_Connector cfg = null;

            cfg = new rfc_Connector();

            IRfcFunction getDataSAP = GlobalData.rfcRepository.CreateFunction("ZFRFC001");
            //getDataSAP.SetValue("P_KUNNR", "ALL");

            IRfcTable IT_DATA = getDataSAP.GetTable("LTLTZTB001");

            IT_DATA.Clear();
            IT_DATA.Append();
            IT_DATA.SetValue("MANDT", "400");
            IT_DATA.SetValue("MATNR", matnr.Text);
            IT_DATA.SetValue("MAKTX", maktx.Text);

            //IT_DATA.Append();
            //IT_DATA.SetValue("MANDT", "400");
            //IT_DATA.SetValue("MATNR", "MATERIAL02");
            //IT_DATA.SetValue("MAKTX", "COBA MATERIAL TEST");

            try
            {
                getDataSAP.Invoke(GlobalData.rfcDestination);
                RfcSessionManager.EndContext(GlobalData.rfcDestination);

                var           exObject    = getDataSAP.GetObject("OUTPUT");
                IRfcStructure exStructure = getDataSAP.GetStructure("LS_ZTB001");
            }
            catch (Exception ex)
            {
                message  = "SAP ZFDLKNA1 ";
                message += ex.Message;

                //RfcSessionManager.EndContext(GlobalData.rfcDestination);
                //Thread.Sleep(1000);
            }

            readdata();
        }
コード例 #19
0
        private void Save_Database(string fingerprint)
        {
            RfcConfigParameters parameters = new RfcConfigParameters();

            parameters[RfcConfigParameters.Name]          = SAPFingerprint.Properties.Settings.Default.Name;
            parameters[RfcConfigParameters.User]          = txtUser.Text;
            parameters[RfcConfigParameters.Password]      = txtPass.Text;
            parameters[RfcConfigParameters.Client]        = SAPFingerprint.Properties.Settings.Default.Client;
            parameters[RfcConfigParameters.Language]      = SAPFingerprint.Properties.Settings.Default.Language;
            parameters[RfcConfigParameters.AppServerHost] = SAPFingerprint.Properties.Settings.Default.AppServerHost;
            parameters[RfcConfigParameters.SystemNumber]  = SAPFingerprint.Properties.Settings.Default.SystemNumber;
            parameters[RfcConfigParameters.SAPRouter]     = SAPFingerprint.Properties.Settings.Default.SAPRouter;
            parameters[RfcConfigParameters.SystemID]      = SAPFingerprint.Properties.Settings.Default.SystemID;

            RfcDestination SapRfcDestination = RfcDestinationManager.GetDestination(parameters);

            RfcSessionManager.BeginContext(SapRfcDestination);

            SapRfcDestination.Ping();
            IRfcFunction function = null;

            try
            {
                function = SapRfcDestination.Repository.CreateFunction("ZFM_READ_WRITE_FINGERPRINT");
                function.SetValue("IM_FINGERPRINT", fingerprint);
                function.SetValue("IM_MODE", "R");
                function.SetValue("IM_UNAME", txtUser.Text);


                function.Invoke(SapRfcDestination);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Error: " + ex.Message);
            }

            RfcSessionManager.EndContext(SapRfcDestination);
            SapRfcDestination = null;
        }
コード例 #20
0
ファイル: SAPDataService.cs プロジェクト: windygu/HaiLan
        public static List <string> getIngnoreEpcs(string date = "")
        {
            List <string> re = new List <string>();

            try
            {
                RfcDestination dest   = RfcDestinationManager.GetDestination(rfcParams);
                RfcRepository  rfcrep = dest.Repository;
                IRfcFunction   myfun  = null;
                myfun = rfcrep.CreateFunction("Z_EW_RF_5000");

                myfun.SetValue("IV_LGNUM", CConfig.mLGNUM);
                if (!string.IsNullOrEmpty(date))
                {
                    myfun.SetValue("IV_DATE", date);
                }

                myfun.Invoke(dest);

                IRfcTable IrfTable = myfun.GetTable("ET_DATA");
                for (int i = 0; i < IrfTable.Count; i++)
                {
                    IrfTable.CurrentIndex = i;
                    string epc = getZiDuan(IrfTable, "EPC");
                    if (!string.IsNullOrEmpty(epc))
                    {
                        re.Add(epc);
                    }
                }

                string result = myfun.GetString("EV_STATUS");
                string sapMsg = myfun.GetString("EV_MSG");
                RfcSessionManager.EndContext(dest);
            }
            catch (Exception)
            {
            }
            return(re);
        }
コード例 #21
0
        /// <summary>
        /// create bp data by job table:BUT000
        /// no use
        /// </summary>
        /// <returns></returns>
        public string CreateBusinessPartner()
        {
            if (rfcDestination == null)
            {
                rfcDestination = RfcDestinationManager.GetDestination(WebApiApplication.destinationConfigName);
            }
            RfcRepository repo             = rfcDestination.Repository;
            IRfcFunction  _BusinessPartner = repo.CreateFunction("BAPI_BUPA_CREATE_FROM_DATA");
            IRfcFunction  _Commit          = repo.CreateFunction("BAPI_TRANSACTION_COMMIT");

            _BusinessPartner.SetValue("PARTNERCATEGORY", 2); //2:org
            _BusinessPartner.SetValue("PARTNERGROUP", 1000); //1000:buyer
            IRfcStructure _CentralData = _BusinessPartner.GetStructure("CENTRALDATA");

            _CentralData.SetValue("SEARCHTERM1", "測試國度");
            _CentralData.SetValue("SEARCHTERM2", "測試資料");
            // _CentralData.SetValue("PARTNERLANGUAGEISO", "EN");

            IRfcStructure _CentraldataOrganization = _BusinessPartner.GetStructure("CENTRALDATAORGANIZATION");

            _CentraldataOrganization.SetValue("NAME1", "LLLLL");
            IRfcStructure _Address = _BusinessPartner.GetStructure("ADDRESSDATA");

            _Address.SetValue("COUNTRY", "TW");
            //_Address.SetValue("LANGU", "EN");
            _Address.SetValue("REGION", "TPE");
            RfcSessionManager.BeginContext(rfcDestination);
            _BusinessPartner.Invoke(rfcDestination);
            _Commit.Invoke(rfcDestination);
            RfcSessionManager.EndContext(rfcDestination);

            string          _BusinessPartnerNumber = _BusinessPartner.GetString("BUSINESSPARTNER");
            DataTable       dtReturn   = ConvertToDotNetTable(_BusinessPartner.GetTable("RETURN"));
            List <ErrorLog> _ErrorList = SetErrorLog(dtReturn, "BAPI_BUPA_CREATE_FROM_DATA", _BusinessPartnerNumber, "");
            List <string>   _Error     = this._errorLogService.MiltiCreate(_ErrorList);

            return(_BusinessPartnerNumber);
        }
コード例 #22
0
        private void button2_Click(object sender, EventArgs e)
        {
            rfc_Connector cfg = null;

            cfg = new rfc_Connector();

            IRfcFunction getDataSAP = GlobalData.rfcRepository.CreateFunction("ZPM_NOTIF_02_REWORK");

            getDataSAP.SetValue("QMNUM", textBox1.Text);

            try
            {
                getDataSAP.Invoke(GlobalData.rfcDestination);
                RfcSessionManager.EndContext(GlobalData.rfcDestination);

                var exObject = getDataSAP.GetObject("MESSAGE");
                MessageBox.Show(exObject.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #23
0
        /// <summary>
        /// you need  excute(se38) ABLM_MODIFY_ITEMS in sap system and set relavant parameter
        /// previous when you use BAPI_SALESORDER_CREATEFROMDAT2 this RFC module
        /// </summary>
        /// <param name="destinationName"></param>
        /// <returns></returns>
        public string CreateOrder(SapSalesOrder salesOrder)
        {
            if (rfcDestination == null)
            {
                rfcDestination = RfcDestinationManager.GetDestination(WebApiApplication.destinationConfigName);
            }
            RfcRepository repo            = rfcDestination.Repository;
            IRfcFunction  _SalesDoc       = repo.CreateFunction("BAPI_SALESORDER_CREATEFROMDAT2");
            IRfcFunction  _SalesDocCommit = repo.CreateFunction("BAPI_TRANSACTION_COMMIT");
            IRfcStructure _SalesHeader    = _SalesDoc.GetStructure("ORDER_HEADER_IN");
            IRfcTable     _SalesItems     = _SalesDoc.GetTable("ORDER_ITEMS_IN");
            IRfcTable     _SalesPartners  = _SalesDoc.GetTable("ORDER_PARTNERS");
            IRfcTable     _SalesSchedule  = _SalesDoc.GetTable("ORDER_SCHEDULES_IN");

            _SalesHeader.SetValue("DOC_TYPE", salesOrder.Header.DOC_TYPE);
            _SalesHeader.SetValue("SALES_ORG", salesOrder.Header.SALES_ORG);
            _SalesHeader.SetValue("DISTR_CHAN", salesOrder.Header.DISTR_CHAN);
            _SalesHeader.SetValue("DIVISION", salesOrder.Header.DIVISION);
            _SalesHeader.SetValue("PURCH_NO_C", salesOrder.Header.PURCH_NO_C);
            //test 採購日期
            _SalesHeader.SetValue("PURCH_DATE", salesOrder.Header.PURCH_DATE);
            foreach (SalesItem si in salesOrder.ItemList)
            {
                IRfcStructure _SalesItemsStruct = _SalesItems.Metadata.LineType.CreateStructure();
                _SalesItemsStruct.SetValue("ITM_NUMBER", si.ITM_NUMBER);
                //_SalesItemsStruct.SetValue("MATERIAL", si.MATERIAL);
                _SalesItemsStruct.SetValue("MATERIAL_LONG", si.MATERIAL);
                _SalesItemsStruct.SetValue("TARGET_QTY", si.TARGET_QTY);
                //test 客戶物料號碼
                _SalesItemsStruct.SetValue("CUST_MAT35", si.CUST_MAT35);
                _SalesItems.Append(_SalesItemsStruct);
            }
            foreach (SalesPartner sp in salesOrder.PartnerList)
            {
                IRfcStructure _SalesPartnersStruct = _SalesPartners.Metadata.LineType.CreateStructure();
                _SalesPartnersStruct.SetValue("PARTN_ROLE", sp.PARTN_ROLE);
                _SalesPartnersStruct.SetValue("PARTN_NUMB", sp.PARTN_NUMB);
                _SalesPartners.Append(_SalesPartnersStruct);
            }
            foreach (SalesSchedule ss in salesOrder.ScheduleList)
            {
                IRfcStructure _SalesScheduleStruct = _SalesSchedule.Metadata.LineType.CreateStructure();
                _SalesScheduleStruct.SetValue("REQ_QTY", ss.REQ_QTY);
                _SalesScheduleStruct.SetValue("ITM_NUMBER", ss.ITM_NUMBER);
                _SalesScheduleStruct.SetValue("SCHED_LINE", ss.SCHED_LINE);
                _SalesScheduleStruct.SetValue("REQ_DATE", ss.REQ_DATE);
                _SalesSchedule.Append(_SalesScheduleStruct);
            }
            ////salesPartnersStruct.SetValue("PARTN_ROLE", "RE");
            ////salesPartnersStruct.SetValue("PARTN_NUMB", "0010000650");
            ////salesPartners.Append(salesPartnersStruct);
            RfcSessionManager.BeginContext(rfcDestination);
            _SalesDoc.Invoke(rfcDestination);
            _SalesDocCommit.Invoke(rfcDestination);
            RfcSessionManager.EndContext(rfcDestination);
            string          _SalesCocument = _SalesDoc.GetString("SALESDOCUMENT");
            DataTable       dtReturn       = ConvertToDotNetTable(_SalesDoc.GetTable("RETURN"));
            List <ErrorLog> _ErrorList     = SetErrorLog(dtReturn, "BAPI_SALESORDER_CREATEFROMDAT2", _SalesCocument, salesOrder.Header.PURCH_NO_C);
            List <string>   _Error         = this._errorLogService.MiltiCreate(_ErrorList);

            return(_SalesCocument);
        }
コード例 #24
0
ファイル: SAPRFC.cs プロジェクト: chittasn/SpoWebApi
        /// <summary>
        /// Below function gets products information.
        /// </summary>
        /// <param name="Productname"></param>
        /// <param name="RegionID"></param>
        /// <param name="RegionName"></param>
        /// <param name="LanguageId"></param>
        /// <param name="LanguageName"></param>
        /// <param name="Materialno"></param>
        /// <param name="MaxHitcount"></param>
        /// <param name="ViewType"></param>
        /// <returns></returns>
        public List <SIISAPMSDSDTO> GetProductsInformation(string RegionID, string RegionName, string LanguageId, string LanguageName, string Productname, string Materialno, int MaxHitcount, string ViewType)
        {
            List <SIISAPMSDSDTO> objMDSDSList = new List <SIISAPMSDSDTO>();
            var rfcDestination = RfcDestinationManager.GetDestination("SIISAP");

            try
            {
                if (rfcDestination != null)
                {
                    var getGateEntryRfc = rfcDestination.Repository.CreateFunction("ZEHS_MSDS_PRTL_F4_LIST_OF_MSDS");
                    /// PRODUCT
                    RfcStructureMetadata metaData      = rfcDestination.Repository.GetStructureMetadata("ZEHS_GEN_PRODS");
                    IRfcStructure        structProduct = metaData.CreateStructure();
                    structProduct.SetValue("BRAND2", Productname);//, "ALKANOX® 240");
                    getGateEntryRfc.SetValue("I_PROD", structProduct);
                    /// REGION
                    RfcStructureMetadata metaDataCountry = rfcDestination.Repository.GetStructureMetadata("ZEHS_GEN_CNTRY");
                    IRfcStructure        structRegions   = metaDataCountry.CreateStructure();
                    structRegions.SetValue("LDEPID", RegionID);    // "SDS_US");
                    structRegions.SetValue("LDEPNAM", RegionName); // "");
                    getGateEntryRfc.SetValue("I_REGION", structRegions);
                    // LANGUAGE
                    RfcStructureMetadata metaDataLanguage = rfcDestination.Repository.GetStructureMetadata("ZEHS_GEN_LNGS");
                    IRfcStructure        strucLanguage    = metaDataLanguage.CreateStructure();
                    strucLanguage.SetValue("SPRAS", LanguageId);   // "E");
                    strucLanguage.SetValue("SPTXT", LanguageName); // "");
                    getGateEntryRfc.SetValue("I_LANGUAGE", strucLanguage);
                    /// MATERIAL NUMBER
                    getGateEntryRfc.SetValue("I_MATNR", Materialno);          // "*");
                    /// MAX HIT COUNT
                    getGateEntryRfc.SetValue("I_MAX_HIT_COUNT", MaxHitcount); // 300);
                    /// I VIEW TYPE
                    getGateEntryRfc.SetValue("I_VIEWTYPE", ViewType);         // "");
                    // RfcSessionManager.BeginContext(rfcDestination);
                    getGateEntryRfc.Invoke(rfcDestination);
                    /// get the table values
                    IRfcTable Report       = getGateEntryRfc.GetTable("E_REPORT_TAB");
                    IRfcTable ObjectReport = getGateEntryRfc.GetTable("E_REPORT_OBJECT_TAB");
                    //Getting exported values from SAP
                    var COUNT       = getGateEntryRfc.GetValue("E_COUNT");
                    var MaxHITCount = getGateEntryRfc.GetValue("E_FLG_MAX_HIT_REACHED");
                    var objRTFT     = getGateEntryRfc.GetValue("E_BRAND2").ToString().Substring(getGateEntryRfc.GetValue("E_BRAND2").ToString().LastIndexOf("=") + 1).Replace("}", "");

                    RfcSessionManager.EndContext(rfcDestination);
                    foreach (var row in Report)
                    {
                        objMDSDSList.Add(new SIISAPMSDSDTO
                        {
                            ID           = row[0].ToString().Substring(row[0].ToString().IndexOf("=") + 1),
                            RECN         = row[1].ToString().Substring(row[1].ToString().IndexOf("=") + 1),
                            LANGU        = row[2].ToString().Substring(row[2].ToString().IndexOf("=") + 1),
                            LANGUTXT     = row[3].ToString().Substring(row[3].ToString().IndexOf("=") + 1),
                            LanguageID   = row[4].ToString().Substring(row[4].ToString().IndexOf("=") + 1),
                            LanguageText = row[5].ToString().Substring(row[5].ToString().IndexOf("=") + 1),
                            Version      = row[6].ToString().Substring(row[6].ToString().IndexOf("=") + 1),
                            REPTYPE      = row[7].ToString().Substring(row[7].ToString().IndexOf("=") + 1),
                            REPTYPETEXT  = row[8].ToString().Substring(row[8].ToString().IndexOf("=") + 1),
                            RVLID        = row[9].ToString().Substring(row[9].ToString().IndexOf("=") + 1),
                            RVLIDTXT     = row[10].ToString().Substring(row[10].ToString().IndexOf("=") + 1),
                            STATUS       = row[11].ToString().Substring(row[11].ToString().IndexOf("=") + 1),
                            STATUSTXT    = row[12].ToString().Substring(row[12].ToString().IndexOf("=") + 1),
                            GENDAT       = row[13].ToString().Substring(row[13].ToString().IndexOf("=") + 1),
                            VALDAT       = row[14].ToString().Substring(row[14].ToString().IndexOf("=") + 1),
                            REMARK       = row[15].ToString().Substring(row[15].ToString().IndexOf("=") + 1),
                            PrdFileName  = objRTFT
                        });
                        var listinfo = objMDSDSList;
                    }

                    rfcDestination = null;
                }
            }
            catch (Exception ex)
            {
                RfcSessionManager.EndContext(rfcDestination);
                rfcDestination = null;
                FilePath       = ConfigurationManager.AppSettings["siteUrl"];
                WriteLog(FilePath, ex.Message);
            }

            return(objMDSDSList);
        }
コード例 #25
0
ファイル: SAP_Common.cs プロジェクト: saiganmei/xcxl
        public bool getSapFunctionToTablePara(string funName, Dictionary <string, string> lstParameters, Dictionary <string, Dictionary <string, object> > lstStructures
                                              , IRfcTable rtbIput, string tableindex
                                              , List <string> ParameterNamesForOut, out Dictionary <string, string> ParametersOutput
                                              , List <string> StructureNamesForOut, out Dictionary <string, IRfcStructure> StructureOutputs
                                              , List <string> tableNamesForOut, out Dictionary <string, IRfcTable> rtbsOutput, ref string strErrMsg)
        {
            try
            {
                RfcRepository repo       = rfcrep;
                IRfcFunction  Z_RFC_ZCOX = repo.CreateFunction(funName);
                RfcSessionManager.BeginContext(dest);
                if (lstParameters != null && lstParameters.Count > 0)
                {
                    foreach (KeyValuePair <string, string> item in lstParameters)
                    {
                        Z_RFC_ZCOX.SetValue(item.Key, item.Value);
                    }
                }
                if (lstStructures != null && lstStructures.Count > 0)
                {
                    foreach (string item in lstStructures.Keys)
                    {
                        IRfcStructure _stru = Z_RFC_ZCOX.GetStructure(item);
                        foreach (KeyValuePair <string, object> _kv in lstStructures[item])
                        {
                            _stru.SetValue(_kv.Key, _kv.Value);
                        }
                    }
                }
                if (rtbIput != null)
                {
                    Z_RFC_ZCOX.SetValue(tableindex, rtbIput);
                }

                Z_RFC_ZCOX.Invoke(dest);
                RfcSessionManager.EndContext(dest);

                //取出返回的表
                if (tableNamesForOut != null && tableNamesForOut.Count > 0)
                {
                    rtbsOutput = new Dictionary <string, IRfcTable>();
                    foreach (string item in tableNamesForOut)
                    {
                        IRfcTable rtb = Z_RFC_ZCOX.GetTable(item);
                        rtbsOutput.Add(item, rtb);
                    }
                }
                else
                {
                    rtbsOutput = null;
                }

                //取出返回参数
                if (ParameterNamesForOut != null && ParameterNamesForOut.Count > 0)
                {
                    ParametersOutput = new Dictionary <string, string>();
                    foreach (string item in ParameterNamesForOut)
                    {
                        string retPara = Z_RFC_ZCOX.GetString(item);
                        ParametersOutput.Add(item, retPara);
                    }
                }
                else
                {
                    ParametersOutput = null;
                }

                //取出返回的结构
                if (StructureNamesForOut != null && StructureNamesForOut.Count > 0)
                {
                    StructureOutputs = new Dictionary <string, IRfcStructure>();
                    foreach (string item in StructureNamesForOut)
                    {
                        IRfcStructure retStru = Z_RFC_ZCOX.GetStructure(item);
                        StructureOutputs.Add(item, retStru);
                    }
                }
                else
                {
                    StructureOutputs = null;
                }

                char statue = Z_RFC_ZCOX.GetChar("EX_TYPE");

                if ("E".Contains(statue))
                {
                    strErrMsg = Z_RFC_ZCOX.GetString("EX_MSG");
                }

                return("S".Contains(statue));
            }
            catch (RfcAbapRuntimeException ex)
            {
                ParametersOutput = null;
                rtbsOutput       = null;
                StructureOutputs = null;
                throw ex;
            }
        }
コード例 #26
0
ファイル: BATCH.cs プロジェクト: radtek/QM
        public async Task BAPI_GOODSMVT_CREATE(IList <GOODSMVT_ITEM> dt)
        {
            try
            {
                RfcDestination dest       = GetDestination();
                RfcRepository  repository = dest.Repository;
                RfcSessionManager.BeginContext(dest);
                IRfcFunction func    = repository.CreateFunction("BAPI_GOODSMVT_CREATE");
                string       message = null;

                IRfcStructure rfcStructGMItem = null;
                IRfcTable     rfcTableGMItem  = func.GetTable("GOODSMVT_ITEM");

                IRfcStructure stru;
                IRfcTable     result;

                //set parm
                rfcStructGMItem = repository.GetStructureMetadata("BAPI2017_GM_ITEM_CREATE").CreateStructure();
                foreach (var item in dt)
                {
                    rfcStructGMItem.SetValue("MATERIAL", item.material);
                    rfcStructGMItem.SetValue("PLANT", item.plant);
                    rfcStructGMItem.SetValue("STGE_LOC", item.stge_loc);
                    rfcStructGMItem.SetValue("BATCH", item.batch);
                    rfcStructGMItem.SetValue("MOVE_TYPE", item.move_type);
                    rfcStructGMItem.SetValue("ENTRY_QNT", item.entry_qnt);
                    rfcStructGMItem.SetValue("COST_OBJ", item.cost_obj);
                    rfcStructGMItem.SetValue("ENTRY_UOM", item.entry_uom);
                }
                rfcTableGMItem.Insert(rfcStructGMItem);

                IRfcStructure rfcStructGMCode = null;
                rfcStructGMCode = func.GetStructure("GOODSMVT_CODE");

                if (dt.Count > 0)
                {
                    if (dt[0].move_type == "291")
                    {
                        rfcStructGMCode.SetValue("GM_CODE", "03");
                    }
                    else if (dt[0].move_type == "292")
                    {
                        rfcStructGMCode.SetValue("GM_CODE", "06");
                    }
                }

                IRfcStructure rfcStructGMHeader = null;
                rfcStructGMHeader = func.GetStructure("GOODSMVT_HEADER");
                rfcStructGMHeader.SetValue("PSTNG_DATE", "20191028");
                rfcStructGMHeader.SetValue("DOC_DATE", "20191028");



                //call function
                log.Debug("BAPI_GOODSMVT_CREATE => Start");
                func.Invoke(dest);
                log.Debug("BAPI_GOODSMVT_CREATE => Done");

                //log result
                result = func.GetTable("RETURN");

                for (int k = 0; k < result.RowCount; k++)
                {
                    stru    = result[k];
                    message = stru.GetValue("MESSAGE").ToString();
                    log.Debug(string.Format("MESSAGE:{0}", message));
                }

                if (result.RowCount == 0)
                {
                    string doc  = func.GetValue("MATERIALDOCUMENT").ToString();
                    string year = func.GetValue("MATDOCUMENTYEAR").ToString();

                    func = repository.CreateFunction("BAPI_TRANSACTION_COMMIT");
                    func.SetValue("WAIT", "X");
                    func.Invoke(dest);

                    stru = func.GetStructure("RETURN");
                    MessageBox.Show(doc);
                }
                else
                {
                    func = repository.CreateFunction("BAPI_TRANSACTION_ROLLBACK");
                    func.Invoke(dest);
                    MessageBox.Show(message);
                }

                RfcSessionManager.EndContext(dest);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #27
0
ファイル: SAP_Common.cs プロジェクト: saiganmei/xcxl
        public bool PostSapFunctionFromListTable(string funName, Dictionary <string, string> lstParameters
                                                 , Dictionary <string, Dictionary <string, object> > lstStructures
                                                 , ref Dictionary <string, string> ParametersOutputs
                                                 , ref Dictionary <string, IRfcStructure> StructureOutputs
                                                 , ref Dictionary <string, IRfcTable> rtbsOutputs
                                                 , Dictionary <string, IRfcTable> lstTable, ref string strErrMsg)
        {
            try
            {
                RfcRepository repo       = rfcrep;
                IRfcFunction  Z_RFC_ZCOX = repo.CreateFunction(funName);
                RfcSessionManager.BeginContext(dest);

                if (lstParameters != null && lstParameters.Count > 0)
                {
                    foreach (KeyValuePair <string, string> item in lstParameters)
                    {
                        Z_RFC_ZCOX.SetValue(item.Key, item.Value);
                    }
                }

                if (lstStructures != null && lstStructures.Count > 0)
                {
                    foreach (string item in lstStructures.Keys)
                    {
                        IRfcStructure _stru = Z_RFC_ZCOX.GetStructure(item);
                        foreach (KeyValuePair <string, object> _kv in lstStructures[item])
                        {
                            _stru.SetValue(_kv.Key, _kv.Value);
                        }
                    }
                }

                if (lstTable != null && lstTable.Count > 0)
                {
                    foreach (KeyValuePair <string, IRfcTable> item in lstTable)
                    {
                        Z_RFC_ZCOX.SetValue(item.Key, item.Value);
                    }
                }

                //if (rfcTable != null && rfcTable.Count > 0)
                //{
                //    Z_RFC_ZCOX.SetValue(rfcTableName, rfcTable);
                //}

                Z_RFC_ZCOX.Invoke(dest);
                RfcSessionManager.EndContext(dest);

                //取出返回的表
                if (rtbsOutputs != null && rtbsOutputs.Count > 0)
                {
                    for (int i = 0; i < rtbsOutputs.Count; i++)
                    {
                        var       _item = rtbsOutputs.ElementAt(i);
                        IRfcTable rtb   = Z_RFC_ZCOX.GetTable(_item.Key);
                        rtbsOutputs[_item.Key] = rtb;
                    }
                }
                else
                {
                    rtbsOutputs = null;
                }

                //取出返回的结构
                if (StructureOutputs != null && StructureOutputs.Count > 0)
                {
                    for (int i = 0; i < StructureOutputs.Count; i++)
                    {
                        var           _item   = StructureOutputs.ElementAt(i);
                        IRfcStructure retStru = Z_RFC_ZCOX.GetStructure(_item.Key);
                        StructureOutputs[_item.Key] = retStru;
                    }
                }
                else
                {
                    StructureOutputs = null;
                }

                return(CreateReturn(rtbsOutputs["RETURN"], ref strErrMsg));
            }
            catch (RfcAbapRuntimeException ex)
            {
                throw ex;
            }
        }
コード例 #28
0
 public void Shutdown()
 {
     RfcSessionManager.EndContext(_rfcDestination);
     _server.Shutdown(true);
 }
コード例 #29
0
        protected override void DefWndProc(ref Message m)
        {
            switch (m.Msg)
            {
            case MESSAGE_CAPTURED_OK:
            {
                MemoryStream ms = new MemoryStream();
                BitmapFormat.GetBitmap(FPBuffer, mfpWidth, mfpHeight, ref ms);
                Bitmap bmp = new Bitmap(ms);
                this.picFPImg.Image = bmp;

                String strShow = zkfp2.BlobToBase64(CapTmp, cbCapTmp);


                if (IsRegister)
                {
                    int ret = zkfp.ZKFP_ERR_OK;
                    int fid = 0, score = 0;
                    ret = zkfp2.DBIdentify(mDBHandle, CapTmp, ref fid, ref score);
                    if (zkfp.ZKFP_ERR_OK == ret)
                    {
                        txtStatus.Text = "This finger was already register";
                        return;
                    }

                    if (RegisterCount > 0 && zkfp2.DBMatch(mDBHandle, CapTmp, RegTmps[RegisterCount - 1]) <= 0)
                    {
                        txtStatus.Text = "Please press the same finger 1 times for the enrollment.";
                        return;
                    }

                    Array.Copy(CapTmp, RegTmps[RegisterCount], cbCapTmp);
                    String strBase64 = zkfp2.BlobToBase64(CapTmp, cbCapTmp);


                    byte[] blob = zkfp2.Base64ToBlob(strBase64);
                    RegisterCount++;

                    Save_Database(strBase64);

                    if (RegisterCount >= REGISTER_FINGER_COUNT)
                    {
                        txtStatus.Text = "Enroll succesfully";

                        IsRegister = false;
                        cbRegTmp   = 1;
                        return;
                    }
                    else
                    {
                        txtStatus.Text = "You need to press the " + (REGISTER_FINGER_COUNT - RegisterCount) + " times fingerprint";
                    }
                }
                else
                {
                    if (cbRegTmp <= 0)
                    {
                        txtStatus.Text = "Please register your finger first!";
                        return;
                    }
                    if (bIdentify)
                    {
                        int ret = zkfp.ZKFP_ERR_OK;
                        int fid = 0, score = 0;
                        ret = zkfp2.DBIdentify(mDBHandle, CapTmp, ref fid, ref score);
                        if (zkfp.ZKFP_ERR_OK == ret)
                        {
                            txtStatus.Text = "Identify succesfully, fid= " + fid + ",score=" + score + "!";
                            return;
                        }
                        else
                        {
                            txtStatus.Text = "Identify failed, ret= " + ret;
                            return;
                        }
                    }
                    else
                    {
                        RfcConfigParameters parameters = new RfcConfigParameters();

                        parameters[RfcConfigParameters.Name]          = SAPFingerprint.Properties.Settings.Default.Name;
                        parameters[RfcConfigParameters.User]          = txtUser.Text;
                        parameters[RfcConfigParameters.Password]      = txtPass.Text;
                        parameters[RfcConfigParameters.Client]        = SAPFingerprint.Properties.Settings.Default.Client;
                        parameters[RfcConfigParameters.Language]      = SAPFingerprint.Properties.Settings.Default.Language;
                        parameters[RfcConfigParameters.AppServerHost] = SAPFingerprint.Properties.Settings.Default.AppServerHost;
                        parameters[RfcConfigParameters.SystemNumber]  = SAPFingerprint.Properties.Settings.Default.SystemNumber;
                        parameters[RfcConfigParameters.SAPRouter]     = SAPFingerprint.Properties.Settings.Default.SAPRouter;
                        parameters[RfcConfigParameters.SystemID]      = SAPFingerprint.Properties.Settings.Default.SystemID;

                        RfcDestination SapRfcDestination = RfcDestinationManager.GetDestination(parameters);
                        RfcSessionManager.BeginContext(SapRfcDestination);

                        SapRfcDestination.Ping();
                        IRfcFunction function = null;

                        try
                        {
                            function = SapRfcDestination.Repository.CreateFunction("ZFM_READ_WRITE_FINGERPRINT");
                            function.SetValue("IM_MODE", "V");

                            IRfcTable gt_table = function.GetTable("EX_FINGERPRINT");

                            function.Invoke(SapRfcDestination);

                            jj = 0;
                            foreach (IRfcStructure row in gt_table)
                            {
                                jj = jj + 1;
                                byte[] blob1 = Convert.FromBase64String(Convert.ToString(row.GetValue(0)));

                                String strBase64 = zkfp2.BlobToBase64(CapTmp, cbCapTmp);

                                byte[] blob2 = Convert.FromBase64String(strBase64.Trim());

                                int ret = zkfp2.DBMatch(mDBHandle, blob1, blob2);
                                if (ret > 0)
                                {
                                    txtStatus.Text = "Selamat Datang!";

                                    vald = ret;
                                    break;
                                }
                                else
                                {
                                    txtStatus.Text = "Maaf and tidak dikenali";
                                }
                                zkfp2.DBClear(mDBHandle);
                            }

                            if (vald > 0)
                            {
                                // function = SapRfcDestination.Repository.CreateFunction("ZFM_READ_WRITE_FINGERPRINT");
                                // function.SetValue("MODE", "V");
                                // function.SetValue("INDX", jj);
                                // function.Invoke(SapRfcDestination);
                            }
                        }
                        catch (Exception ex)
                        {
                            System.Windows.Forms.MessageBox.Show("Error: " + ex.Message);
                        }

                        RfcSessionManager.EndContext(SapRfcDestination);
                        SapRfcDestination = null;
                    }
                }
            }
            break;

            default:
                base.DefWndProc(ref m);
                break;
            }
        }
コード例 #30
0
ファイル: InvoiceDet.cs プロジェクト: Rashmi-Salaria/Finocart
        public InvoiceValueModel GetInvoiceValue(RfcDestination rfcDest, string InvoiceDocNumber, string FISCALYEAR)
        {
            List <InvoiceValueModel> lstInvoiceValueDet = new List <InvoiceValueModel>();
            InvoiceValueModel        invoiceValueModel  = new InvoiceValueModel();
            RfcDestination           SAPRfcDestination  = RfcDestinationManager.GetDestination("accelyides");

            RfcRepository rfcrep = SAPRfcDestination.Repository;
            IRfcFunction  BapiGetCompanyDetail = null;


            BapiGetCompanyDetail = rfcrep.CreateFunction("BAPI_INCOMINGINVOICE_GETDETAIL");
            BapiGetCompanyDetail.SetValue("INVOICEDOCNUMBER", InvoiceDocNumber);
            BapiGetCompanyDetail.SetValue("FISCALYEAR", FISCALYEAR);
            BapiGetCompanyDetail.Invoke(rfcDest);
            IRfcTable tblReturn = BapiGetCompanyDetail.GetTable("ITEMDATA");
            DataTable TBL       = tblReturn.ToDataTable("TBL");

            IRfcTable tblTAXReturn = BapiGetCompanyDetail.GetTable("TAXDATA");
            DataTable TBLTaxReturn = tblTAXReturn.ToDataTable("TBL");

            IRfcTable tblWithTAXReturn = BapiGetCompanyDetail.GetTable("WITHTAXDATA");
            DataTable DtWithTAXReturn  = tblWithTAXReturn.ToDataTable("TBL");

            IRfcTable tblVendorSplitData = BapiGetCompanyDetail.GetTable("VENDORITEMSPLITDATA");
            DataTable DtVendorSplitData  = tblVendorSplitData.ToDataTable("TBL");

            //for (int i = 0; i < TBL.Rows.Count; i++)
            //{
            //    InvoiceValueModel InvoiceValueModel = new InvoiceValueModel();

            //    InvoiceValueModel.REF_DOC = TBL.Rows[i]["REF_DOC"].ToString();
            //   // invoiceValueModel.lstInvoiceValue.Add(InvoiceValueModel);
            //}
            invoiceValueModel.lstItemInvoiceDet = (from DataRow row in TBL.Rows
                                                   select new InvoiceValueModel
            {
                INVOICE_DOC_ITEM = row["INVOICE_DOC_ITEM"].ToString(),
                PO_NUMBER = row["INVOICE_DOC_ITEM"].ToString(),
                PO_ITEM = row["PO_ITEM"].ToString(),
                SERIAL_NO = row["SERIAL_NO"].ToString(),
                REF_DOC = row["REF_DOC"].ToString(),
                REF_DOC_YEAR = row["REF_DOC_YEAR"].ToString(),
                REF_DOC_IT = row["REF_DOC_IT"].ToString(),
                TAX_CODE = row["TAX_CODE"].ToString(),
                ITEM_AMOUNT = row["ITEM_AMOUNT"].ToString(),
                QUANTITY = row["QUANTITY"].ToString(),
                PO_UNIT = row["PO_UNIT"].ToString(),
                PO_UNIT_ISO = row["PO_UNIT_ISO"].ToString()
            }).ToList();

            invoiceValueModel.lstInvoiceTAXDet = (from DataRow row in TBLTaxReturn.Rows
                                                  select new InvoiceValueModel
            {
                TAX_CODE = row["TAX_CODE"].ToString(),
                TAX_AMOUNT = row["TAX_AMOUNT"].ToString(),
                VEND_ERROR = row["VEND_ERROR"].ToString(),
                TAX_ERROR = row["TAX_ERROR"].ToString(),
            }).ToList();

            invoiceValueModel.lstWithTAXInvoiceDet = (from DataRow row in DtWithTAXReturn.Rows
                                                      select new InvoiceValueModel
            {
                SPLIT_KEY = row["SPLIT_KEY"].ToString(),
                WI_TAX_TYPE = row["WI_TAX_TYPE"].ToString()
            }).ToList();

            invoiceValueModel.lstVEndorItemSolitData = (from DataRow row in DtVendorSplitData.Rows
                                                        select new InvoiceValueModel
            {
                SPLIT_KEY = row["SPLIT_KEY"].ToString(),
                SPLIT_AMOUNT = row["SPLIT_AMOUNT"].ToString()
            }).ToList();

            IRfcStructure IRS_OS_HEADER = BapiGetCompanyDetail.GetStructure("HEADERDATA");

            invoiceValueModel.INV_DOC_NO     = IRS_OS_HEADER.GetValue("INV_DOC_NO").ToString();
            invoiceValueModel.USERNAME       = IRS_OS_HEADER.GetValue("FISC_YEAR").ToString();
            invoiceValueModel.FISC_YEAR      = IRS_OS_HEADER.GetValue("USERNAME").ToString();
            invoiceValueModel.INVOICEE_IND   = IRS_OS_HEADER.GetValue("INVOICE_IND").ToString();
            invoiceValueModel.DOC_TYPE       = IRS_OS_HEADER.GetValue("DOC_TYPE").ToString();
            invoiceValueModel.DOC_DATE       = DateTime.Parse(IRS_OS_HEADER.GetValue("DOC_DATE").ToString());
            invoiceValueModel.PSTNG_DATE     = DateTime.Parse(IRS_OS_HEADER.GetValue("PSTNG_DATE").ToString());
            invoiceValueModel.USERNAME       = IRS_OS_HEADER.GetValue("USERNAME").ToString();
            invoiceValueModel.REF_DOC_NO     = IRS_OS_HEADER.GetValue("REF_DOC_NO").ToString();
            invoiceValueModel.COMP_CODE      = IRS_OS_HEADER.GetValue("COMP_CODE").ToString();
            invoiceValueModel.DIFF_INV       = IRS_OS_HEADER.GetValue("DIFF_INV").ToString();
            invoiceValueModel.CURRENCY       = IRS_OS_HEADER.GetValue("CURRENCY").ToString();
            invoiceValueModel.CURRENCY_ISO   = IRS_OS_HEADER.GetValue("CURRENCY_ISO").ToString();
            invoiceValueModel.EXCH_RATE      = IRS_OS_HEADER.GetValue("EXCH_RATE").ToString();
            invoiceValueModel.EXCH_RATE_V    = IRS_OS_HEADER.GetValue("EXCH_RATE_V").ToString();
            invoiceValueModel.GROSS_AMT      = IRS_OS_HEADER.GetValue("GROSS_AMNT").ToString();
            invoiceValueModel.BLINE_DATE     = DateTime.Parse(IRS_OS_HEADER.GetValue("BLINE_DATE").ToString());
            invoiceValueModel.ENTRY_DATE     = DateTime.Parse(IRS_OS_HEADER.GetValue("ENTRY_DATE").ToString());
            invoiceValueModel.ENTRY_TIME     = DateTime.Parse(IRS_OS_HEADER.GetValue("ENTRY_TIME").ToString());
            invoiceValueModel.DISCNT         = IRS_OS_HEADER.GetValue("DISCNT").ToString();
            invoiceValueModel.INVOICE_STATUS = IRS_OS_HEADER.GetValue("INVOICE_STATUS").ToString();

            //Console.WriteLine(invoiceValueModel.Value);
            //Console.ReadKey();
            RfcSessionManager.EndContext(rfcDest);

            return(invoiceValueModel);
        }