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);
        }
 public static void closeContextIfNeeded(HttpContext currentContext, String sapClientName, RfcDestination destination)
 {
     if (!isManualContext(currentContext, sapClientName) && !isStatelessRegion(currentContext, sapClientName))
     {
         RfcSessionManager.EndContext(destination);
     }
 }
Beispiel #3
0
        /// <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);
        }
Beispiel #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);
            }
        }
Beispiel #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);
        }
Beispiel #6
0
        /// <summary>
        /// End the current Session/Context.
        /// </summary>
        public void EndSession()
        {
            if (SessionProvider != null)
            {
                RfcSessionManager.UnregisterSessionProvider(SessionProvider);
                SessionProvider = null;
            }

            RfcSessionManager.EndContext(_connection.Destination);
        }
Beispiel #7
0
        // 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"));
        }
Beispiel #8
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);
            }
        }
Beispiel #9
0
        /// <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;
            }
        }
Beispiel #10
0
        /// <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);
        }
Beispiel #11
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);
        }
Beispiel #12
0
        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();
        }
Beispiel #13
0
        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);
        }
        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;
        }
Beispiel #15
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);
        }
Beispiel #16
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);
            }
        }
Beispiel #17
0
        /// <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);
        }
Beispiel #18
0
        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;
            }
        }
Beispiel #19
0
        public string CreateSalesArea(string number)
        {
            if (rfcDestination == null)
            {
                rfcDestination = RfcDestinationManager.GetDestination(WebApiApplication.destinationConfigName);
            }
            RfcRepository repo      = rfcDestination.Repository;
            IRfcFunction  _CUSTOMER = repo.CreateFunction("RFC_CVI_EI_INBOUND_MAIN");

            _CUSTOMER.SetValue("IV_DOCOMMIT", "X");// required
            //IRfcFunction _Commit = repo.CreateFunction("BAPI_TRANSACTION_COMMIT");
            IRfcTable     _IT_CUST_GENERAL       = _CUSTOMER.GetTable("IT_CUST_GENERAL");
            IRfcStructure _IT_CUST_GENERALStruct = _IT_CUST_GENERAL.Metadata.LineType.CreateStructure();

            _IT_CUST_GENERALStruct.SetValue("RUN_ID", "2");
            _IT_CUST_GENERALStruct.SetValue("KUNNR", number);
            _IT_CUST_GENERALStruct.SetValue("OBJECT_TASK", "I");
            _IT_CUST_GENERALStruct.SetValue("BAHNE", "25");
            _IT_CUST_GENERAL.Append(_IT_CUST_GENERALStruct);

            IRfcTable     _IT_CUST_SALES       = _CUSTOMER.GetTable("IT_CUST_SALES");
            IRfcStructure _IT_CUST_SALESStruct = _IT_CUST_SALES.Metadata.LineType.CreateStructure();

            _IT_CUST_SALESStruct.SetValue("RUN_ID", "2");
            _IT_CUST_SALESStruct.SetValue("VKORG", "1000");
            _IT_CUST_SALESStruct.SetValue("VTWEG", "00");
            _IT_CUST_SALESStruct.SetValue("SPART", "00");
            _IT_CUST_SALESStruct.SetValue("KALKS", "1");
            _IT_CUST_SALESStruct.SetValue("VSBED", "01");
            _IT_CUST_SALESStruct.SetValue("WAERS", "USD");

            _IT_CUST_SALESStruct.SetValue("KDGRP", "02");
            _IT_CUST_SALESStruct.SetValue("KURST", "E");
            _IT_CUST_SALESStruct.SetValue("KONDA", "02");
            _IT_CUST_SALESStruct.SetValue("BZIRK", "US");
            _IT_CUST_SALESStruct.SetValue("INCO1", "EXW");
            _IT_CUST_SALESStruct.SetValue("INCO2_L", "EXW");
            _IT_CUST_SALES.Append(_IT_CUST_SALESStruct);

            IRfcTable     _IT_CUST_TAX_INDICATOR       = _CUSTOMER.GetTable("IT_CUST_TAX_INDICATOR");
            IRfcStructure _IT_CUST_TAX_INDICATORStruct = _IT_CUST_TAX_INDICATOR.Metadata.LineType.CreateStructure();

            _IT_CUST_TAX_INDICATORStruct.SetValue("RUN_ID", "2");
            _IT_CUST_TAX_INDICATORStruct.SetValue("ALAND", "CN");
            _IT_CUST_TAX_INDICATORStruct.SetValue("TATYP", "MWST");
            _IT_CUST_TAX_INDICATORStruct.SetValue("TAXKD", "A");
            _IT_CUST_TAX_INDICATOR.Append(_IT_CUST_TAX_INDICATORStruct);
            IRfcStructure _IT_CUST_TAX_INDICATORStruct2 = _IT_CUST_TAX_INDICATOR.Metadata.LineType.CreateStructure();

            _IT_CUST_TAX_INDICATORStruct2.SetValue("RUN_ID", "2");
            _IT_CUST_TAX_INDICATORStruct2.SetValue("ALAND", "TW");
            _IT_CUST_TAX_INDICATORStruct2.SetValue("TATYP", "MWST");
            _IT_CUST_TAX_INDICATORStruct2.SetValue("TAXKD", "6");
            _IT_CUST_TAX_INDICATOR.Append(_IT_CUST_TAX_INDICATORStruct2);

            IRfcTable     _IT_CUST_SALES_FUNCTIONS       = _CUSTOMER.GetTable("IT_CUST_SALES_FUNCTIONS");
            IRfcStructure _IT_CUST_SALES_FUNCTIONSStruct = _IT_CUST_SALES_FUNCTIONS.Metadata.LineType.CreateStructure();

            _IT_CUST_SALES_FUNCTIONSStruct.SetValue("RUN_ID", "2");
            _IT_CUST_SALES_FUNCTIONSStruct.SetValue("VKORG", "1000");
            _IT_CUST_SALES_FUNCTIONSStruct.SetValue("VTWEG", "00");
            _IT_CUST_SALES_FUNCTIONSStruct.SetValue("SPART", "00");
            _IT_CUST_SALES_FUNCTIONSStruct.SetValue("PARVW", "SE");
            _IT_CUST_SALES_FUNCTIONSStruct.SetValue("KNREF", "22");
            _IT_CUST_SALES_FUNCTIONS.Append(_IT_CUST_SALES_FUNCTIONSStruct);
            RfcSessionManager.BeginContext(rfcDestination);
            _CUSTOMER.Invoke(rfcDestination);
            // _Commit.Invoke(rfcDestination);
            RfcSessionManager.EndContext(rfcDestination);
            DataTable       dtReturn   = ConvertToDotNetTable(_CUSTOMER.GetTable("CT_RETURN"));
            List <ErrorLog> _ErrorList = new List <ErrorLog>();
            string          _Number    = "";

            if (dtReturn.Rows.Count > 0)
            {
                _Number    = dtReturn.Rows[0]["OBJECT_KEY"].ToString() == "" ? "" : dtReturn.Rows[0]["OBJECT_KEY"].ToString();
                _ErrorList = SetErrorLog(dtReturn, "RFC_CVI_EI_INBOUND_MAIN", _Number, "");
            }
            return("");
        }
Beispiel #20
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);
        }
        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;
            }
        }
Beispiel #22
0
        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);
        }
Beispiel #23
0
        /// <summary>
        /// 1. if no parameter :IV_DOCOMMIT then no effect
        /// 2. RUN_ID:if not same number then no effect
        /// 3. IT_BP_GENERAL-OBJECT_TASK: insert mode  I
        /// </summary>
        /// <returns></returns>
        public string CreateBP()
        {
            if (rfcDestination == null)
            {
                rfcDestination = RfcDestinationManager.GetDestination(WebApiApplication.destinationConfigName);
            }
            RfcRepository repo      = rfcDestination.Repository;
            IRfcFunction  _CUSTOMER = repo.CreateFunction("RFC_CVI_EI_INBOUND_MAIN");

            _CUSTOMER.SetValue("IV_DOCOMMIT", "X"); //required
            //IRfcFunction _Commit = repo.CreateFunction("BAPI_TRANSACTION_COMMIT");
            IRfcTable     _IT_BP_GENERAL       = _CUSTOMER.GetTable("IT_BP_GENERAL");
            IRfcStructure _IT_BP_GENERALStruct = _IT_BP_GENERAL.Metadata.LineType.CreateStructure();

            _IT_BP_GENERALStruct.SetValue("RUN_ID", "1");
            _IT_BP_GENERALStruct.SetValue("OBJECT_TASK", "I");
            _IT_BP_GENERALStruct.SetValue("BPARTNER", "");
            _IT_BP_GENERALStruct.SetValue("NAME1", "LLLLL");
            _IT_BP_GENERALStruct.SetValue("CATEGORY", 2);//required
            _IT_BP_GENERALStruct.SetValue("GROUPING", "1000");
            _IT_BP_GENERALStruct.SetValue("SEARCHTERM1", "國度");
            _IT_BP_GENERALStruct.SetValue("SEARCHTERM2", "資料");
            _IT_BP_GENERALStruct.SetValue("FOUNDATIONDATE", DateTime.Now.ToString("yyyyMMdd"));
            _IT_BP_GENERALStruct.SetValue("TITLE_KEY", "");
            _IT_BP_GENERALStruct.SetValue("AUTHORIZATIONGROUP", "");
            _IT_BP_GENERALStruct.SetValue("PARTNEREXTERNAL", "");
            _IT_BP_GENERAL.Append(_IT_BP_GENERALStruct);
            IRfcTable     _IT_BP_ROLE        = _CUSTOMER.GetTable("IT_BP_ROLE");
            IRfcStructure _IT_BP_ROLEStruct  = _IT_BP_ROLE.Metadata.LineType.CreateStructure();
            IRfcStructure _IT_BP_ROLEStruct2 = _IT_BP_ROLE.Metadata.LineType.CreateStructure();

            _IT_BP_ROLEStruct.SetValue("RUN_ID", "1"); //required
            _IT_BP_ROLEStruct.SetValue("DATA_KEY", "FLCU00");
            _IT_BP_ROLEStruct.SetValue("ROLECATEGORY", "2");
            _IT_BP_ROLE.Append(_IT_BP_ROLEStruct);
            _IT_BP_ROLEStruct2.SetValue("RUN_ID", "1");//required
            _IT_BP_ROLEStruct2.SetValue("DATA_KEY", "1000");
            _IT_BP_ROLEStruct2.SetValue("ROLECATEGORY", "2");
            _IT_BP_ROLE.Append(_IT_BP_ROLEStruct2);
            IRfcTable     _IT_BP_ADDRESS      = _CUSTOMER.GetTable("IT_BP_ADDRESS");
            IRfcStructure _IT_BP_ADDRESStruct = _IT_BP_ADDRESS.Metadata.LineType.CreateStructure();

            _IT_BP_ADDRESStruct.SetValue("RUN_ID", "1");//required
            _IT_BP_ADDRESStruct.SetValue("STANDARDADDRESS", "X");
            _IT_BP_ADDRESStruct.SetValue("COUNTRY", "US");
            _IT_BP_ADDRESStruct.SetValue("LANGUISO", "EN");
            _IT_BP_ADDRESStruct.SetValue("LANGU", "E");
            _IT_BP_ADDRESS.Append(_IT_BP_ADDRESStruct);
            RfcSessionManager.BeginContext(rfcDestination);
            _CUSTOMER.Invoke(rfcDestination);
            //_Commit.Invoke(rfcDestination);
            RfcSessionManager.EndContext(rfcDestination);
            DataTable       dtReturn   = ConvertToDotNetTable(_CUSTOMER.GetTable("CT_RETURN"));
            List <ErrorLog> _ErrorList = new List <ErrorLog>();
            string          _Number    = "";

            if (dtReturn.Rows.Count > 0)
            {
                _Number    = dtReturn.Rows[0]["OBJECT_KEY"].ToString() == "" ? "" : dtReturn.Rows[0]["OBJECT_KEY"].ToString();
                _ErrorList = SetErrorLog(dtReturn, "RFC_CVI_EI_INBOUND_MAIN", _Number, "");
            }
            List <string> _Error = this._errorLogService.MiltiCreate(_ErrorList);

            //test
            //RfcRepository repo2 = rfcDestination.Repository;
            //IRfcFunction _CUSTOMER2 = repo2.CreateFunction("RFC_CVI_EI_INBOUND_MAIN");
            //_CUSTOMER2.SetValue("IV_DOCOMMIT", "X");
            //IRfcFunction _Commit2 = repo.CreateFunction("BAPI_TRANSACTION_COMMIT");
            //IRfcTable _IT_BP_GENERAL2 = _CUSTOMER2.GetTable("IT_BP_GENERAL");
            //IRfcStructure _IT_BP_GENERAL2Struct = _IT_BP_GENERAL2.Metadata.LineType.CreateStructure();
            //_IT_BP_GENERAL2Struct.SetValue("RUN_ID", "1");
            //_IT_BP_GENERAL2Struct.SetValue("OBJECT_TASK", "U");
            //_IT_BP_GENERAL2Struct.SetValue("BPARTNER", "0010002183");
            //_IT_BP_GENERAL2Struct.SetValue("SEARCHTERM1", "國度1234");
            //_IT_BP_GENERAL2.Append(_IT_BP_GENERAL2Struct);
            //RfcSessionManager.BeginContext(rfcDestination);
            //_CUSTOMER2.Invoke(rfcDestination);
            //_Commit2.Invoke(rfcDestination);
            //RfcSessionManager.EndContext(rfcDestination);
            //DataTable dtReturn2 = ConvertToDotNetTable(_CUSTOMER2.GetTable("CT_RETURN"));
            return(_Number);
        }
Beispiel #24
0
        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;
            }
        }
Beispiel #25
0
        public static void PostSAPData(PlanningFunctionGroup costPlanGroup, int functionCount)
        {
            lock (m_syncObject)
            {
                if (costPlanGroup.FunctionList.Count > 0)
                {
                    IRfcFunction sapPostCostPlanFunction = SapConnection.GetObject().CurrentDestination.Repository.CreateFunction("BAPI_COSTACTPLN_POSTPRIMCOST");
                    IRfcFunction sapCommitWorkFunction   = SapConnection.GetObject().CurrentDestination.Repository.CreateFunction("BAPI_TRANSACTION_COMMIT");
                    IRfcTable    returnTable             = null;

                    try
                    {
                        IRfcStructure headerInfoStructure = sapPostCostPlanFunction.GetStructure("HEADERINFO");                       // HEADER_INFO

                        headerInfoStructure.SetValue("CO_AREA", ((CostPlan)costPlanGroup.FunctionList[0]).ControllingArea);           // 3
                        headerInfoStructure.SetValue("FISC_YEAR", ((CostPlan)costPlanGroup.FunctionList[0]).FiscalYear);              // 4
                        headerInfoStructure.SetValue("PERIOD_FROM", ((CostPlan)costPlanGroup.FunctionList[0]).PeriodFrom);            // 5
                        headerInfoStructure.SetValue("PERIOD_TO", ((CostPlan)costPlanGroup.FunctionList[0]).PeriodTo);                // 6
                        headerInfoStructure.SetValue("VERSION", ((CostPlan)costPlanGroup.FunctionList[0]).Version);                   // 8
                        headerInfoStructure.SetValue("DOC_HDR_TX", ((CostPlan)costPlanGroup.FunctionList[0]).DocumentHeaderText);     // 9
                        headerInfoStructure.SetValue("PLAN_CURRTYPE", ((CostPlan)costPlanGroup.FunctionList[0]).PlanningCurrency);    // 10
                        sapPostCostPlanFunction.SetValue("DELTA", ((CostPlan)costPlanGroup.FunctionList[0]).Delta);                   // 11

                        foreach (IPlanningFunction myFunction in costPlanGroup.FunctionList)
                        {
                            try
                            {
                                IRfcTable coObjectTable = sapPostCostPlanFunction.GetTable("COOBJECT");                                   // OBJECT

                                string objectIndex = ((CostPlan)myFunction).ObjectIndex.ToString("000000");
                                string valueIndex  = ((CostPlan)myFunction).ValueIndex.ToString("000000");

                                coObjectTable.Append();

                                try
                                {
                                    if (coObjectTable.GetValue("OBJECT_INDEX") != null)
                                    {
                                        if (((string)coObjectTable.GetValue("OBJECT_INDEX")) != objectIndex)
                                        {
                                            coObjectTable.SetValue("OBJECT_INDEX", ((CostPlan)myFunction).ObjectIndex.ToString("000000"));  // Calculated
                                        }
                                    }
                                    else
                                    {
                                        coObjectTable.SetValue("OBJECT_INDEX", ((CostPlan)myFunction).ObjectIndex.ToString("000000"));     // Calculated
                                    }
                                }
                                catch (Exception ex)
                                {
                                    coObjectTable.SetValue("OBJECT_INDEX", ((CostPlan)myFunction).ObjectIndex.ToString("000000"));
                                }

                                coObjectTable.SetValue("COSTCENTER", ((CostPlan)myFunction).CostCenter);                    // 11
                                coObjectTable.SetValue("ACTTYPE", ((CostPlan)myFunction).ActivityType);                     // 13
                                coObjectTable.SetValue("ORDERID", ((CostPlan)myFunction).OrderID);                          // 14
                                coObjectTable.SetValue("WBS_ELEMENT", ((CostPlan)myFunction).WBSElement);                   // 15

                                IRfcTable totValueTable = sapPostCostPlanFunction.GetTable("TOTVALUE");                     // TOT_VALUE

                                totValueTable.Append();
                                totValueTable.SetValue("VALUE_INDEX", ((CostPlan)myFunction).ValueIndex.ToString("000000"));     // Calculated

                                if (((CostPlan)myFunction).FixedInputValue != string.Empty)
                                {
                                    totValueTable.SetValue("FIX_VALUE", ((CostPlan)myFunction).FixedInputValue);                // 2
                                }
                                else
                                {
                                    totValueTable.SetValue("FIX_VALUE", "0");
                                }

                                totValueTable.SetValue("DIST_KEY_FIX_VAL", ((CostPlan)myFunction).DistributionKey);         // 6
                                totValueTable.SetValue("COST_ELEM", ((CostPlan)myFunction).CostElement);                    // 12
                                totValueTable.SetValue("FUNCTION", ((CostPlan)myFunction).FunctionalArea);                  // 16
                                totValueTable.SetValue("FUND", ((CostPlan)myFunction).Fund);                                // 17
                                totValueTable.SetValue("GRANT_NBR", ((CostPlan)myFunction).Grant);                          // 18
                                totValueTable.SetValue("TRANS_CURR", ((CostPlan)myFunction).TransactionCurrency);           // 19


                                IRfcTable indexTable = sapPostCostPlanFunction.GetTable("INDEXSTRUCTURE");
                                // IDX_STRUCTURE

                                indexTable.Append();
                                indexTable.SetValue("OBJECT_INDEX", ((CostPlan)myFunction).ObjectIndex.ToString("000000"));
                                indexTable.SetValue("VALUE_INDEX", ((CostPlan)myFunction).ValueIndex.ToString("000000"));
                                indexTable.SetValue("ATTRIB_INDEX", "000000");

                                myFunction.Updated = true;
                            }
                            catch (Exception ex)
                            {
                                myFunction.ValidationResult = ex.Message;
                            }
                        }
                    }
                    catch (Exception exp)
                    {
                        foreach (IPlanningFunction myFunction in costPlanGroup.FunctionList)
                        {
                            myFunction.ValidationResult = exp.Message;
                        }
                    }

                    try
                    {
                        RfcSessionManager.BeginContext(SapConnection.GetObject().CurrentDestination);

                        sapPostCostPlanFunction.Invoke(SapConnection.GetObject().CurrentDestination);
                        sapCommitWorkFunction.Invoke(SapConnection.GetObject().CurrentDestination);

                        RfcSessionManager.EndContext(SapConnection.GetObject().CurrentDestination);
                    }
                    catch (Exception ex)
                    {
                        DialogResult r = MessageBox.Show("SAP Authorization Error: " + ex.Message, "Error",
                                                         System.Windows.Forms.MessageBoxButtons.OK, MessageBoxIcon.Error,
                                                         MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
                        if (r == DialogResult.OK)
                        {
                        }

                        ReturnProgressDataForm.CancelProcess();

                        return;
                    }


                    returnTable = sapPostCostPlanFunction.GetTable("RETURN");


                    foreach (IPlanningFunction myFunction in costPlanGroup.FunctionList)
                    {
                        if (!SAPRequest.ReturnValuesList.ContainsKey(myFunction.Signature))
                        {
                            SAPRequest.ReturnValuesList.Add(myFunction.Signature, myFunction);
                        }
                    }

                    if (returnTable.RowCount > 0)
                    {
                        try
                        {
                            string logPath = LogFile.CheckCreateLogFolder() + "\\PWLogValOnly" + DateTime.Now.ToString("(dd-MMM-yyyy-HH-mm-ss-f)") + ".txt";
                            if (!File.Exists(logPath))
                            {
                                using (TextWriter writer = File.CreateText(logPath))
                                {
                                    writer.WriteLine("VALIDATION AND POST: " + DateTime.Now.ToString("(dd-MMM-yyyy-HH-mm-ss-f)"));
                                    writer.WriteLine(" ");
                                    for (int y = 0; y <= (returnTable.RowCount - 1); y += 1)
                                    {
                                        for (int z = 0; z <= (returnTable[y].ElementCount - 1); z += 1)
                                        {
                                            string par = returnTable[y][z].Metadata.Name;
                                            string val = returnTable[y].GetString(z);

                                            string messageLine = par + " : " + val;
                                            writer.WriteLine(messageLine);
                                        }
                                        writer.WriteLine(" ");
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            //MessageBox.Show(ex.Message)
                        }


                        for (int j = 0; j <= (returnTable.RowCount - 1); j++)
                        {
                            int    row     = Convert.ToInt32(returnTable[j].GetString("ROW")) - 1;
                            string message = returnTable[j].GetString("MESSAGE");

                            if (row < 0)
                            {
                                row = 0;
                            }

                            string rType     = string.Empty;
                            string messageV1 = string.Empty;
                            string messageV2 = string.Empty;
                            string messageV3 = string.Empty;
                            string messageV4 = string.Empty;
                            string rNumber   = string.Empty;

                            rType     = returnTable[j].GetString("TYPE");
                            messageV1 = returnTable[j].GetString("MESSAGE_V1");
                            messageV2 = returnTable[j].GetString("MESSAGE_V2");

                            for (int i = 0; i <= (costPlanGroup.FunctionList.Count - 1); i++)
                            {
                                int elementLocation = SAPRequest.GetObject().TotalProcessedBySAP + i;
                                if (elementLocation < 0)
                                {
                                    elementLocation = 0;
                                }

                                string costElement = ((CostPlan)SAPRequest.ReturnValuesList.Values.ElementAt(elementLocation)).CostElement;
                                string costCenter  = ((CostPlan)SAPRequest.ReturnValuesList.Values.ElementAt(elementLocation)).CostCenter;

                                try
                                {
                                    messageV1 = messageV1.TrimStart('0');
                                    messageV2 = messageV2.TrimStart('0');
                                }
                                catch (Exception ex)
                                {
                                }

                                try
                                {
                                    if (i == row && !string.IsNullOrEmpty(message))
                                    {
                                        SAPRequest.ReturnValuesList.Values.ElementAt(elementLocation).Result = message;
                                    }
                                    else if (i != row && rType == "E")
                                    {
                                        try
                                        {
                                            if (messageV1 == costElement || messageV2 == costElement)
                                            {
                                                // account for incrementing batch number
                                                SAPRequest.ReturnValuesList.Values.ElementAt(elementLocation).Result = message;
                                            }
                                            else if (messageV1 != costElement && messageV1 != costCenter && row == 0)
                                            {
                                                rNumber = returnTable[j].GetString("NUMBER");
                                                if (rNumber != string.Empty)
                                                {
                                                    SAPRequest.ReturnValuesList.Values.ElementAt(elementLocation).Result = message;
                                                    if (ReturnProgressDataForm.OperationCancelled)
                                                    {
                                                        break;
                                                    }
                                                }
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                        }
                                    }
                                    else if (rType == "I")
                                    {
                                        foreach (IPlanningFunction myFunction in costPlanGroup.FunctionList)
                                        {
                                            SAPRequest.ReturnValuesList[myFunction.Signature].Result = message;
                                            if (ReturnProgressDataForm.OperationCancelled)
                                            {
                                                break;
                                            }
                                        }
                                        return;
                                    }
                                }
                                catch (Exception ex)
                                {
                                }
                                if (ReturnProgressDataForm.OperationCancelled)
                                {
                                    break;
                                }
                            }
                            if (ReturnProgressDataForm.OperationCancelled)
                            {
                                break;
                            }
                        }
                        foreach (IPlanningFunction myFunction in costPlanGroup.FunctionList)
                        {
                            if (SAPRequest.ReturnValuesList[myFunction.Signature].Result == null | SAPRequest.ReturnValuesList[myFunction.Signature].Result == string.Empty)
                            {
                                SAPRequest.ReturnValuesList[myFunction.Signature].Result = "pwValidated";
                            }
                            if (ReturnProgressDataForm.OperationCancelled)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        foreach (IPlanningFunction myFunction in costPlanGroup.FunctionList)
                        {
                            SAPRequest.ReturnValuesList[myFunction.Signature].Result = "pwValidated";
                            if (ReturnProgressDataForm.OperationCancelled)
                            {
                                break;
                            }
                        }
                    }
                }
            }
        }
Beispiel #26
0
        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;
            }
        }
Beispiel #27
0
 public void Shutdown()
 {
     RfcSessionManager.EndContext(_rfcDestination);
     _server.Shutdown(true);
 }
Beispiel #28
0
        /// <summary>
        /// no use
        /// </summary>
        /// <param name="number"></param>
        /// <returns></returns>
        public string CreateCustomer(string number)
        {
            if (rfcDestination == null)
            {
                rfcDestination = RfcDestinationManager.GetDestination(WebApiApplication.destinationConfigName);
            }
            RfcRepository repo              = rfcDestination.Repository;
            IRfcFunction  _CUSTOMER         = repo.CreateFunction("BAPI_CUSTOMER_CREATEFROMDATA1");
            IRfcFunction  _Commit           = repo.CreateFunction("BAPI_TRANSACTION_COMMIT");
            IRfcStructure _PI_COPYREFERENCE = _CUSTOMER.GetStructure("PI_COPYREFERENCE");

            _PI_COPYREFERENCE.SetValue("SALESORG", "1000");
            _PI_COPYREFERENCE.SetValue("DISTR_CHAN", "00");
            _PI_COPYREFERENCE.SetValue("DIVISION", "00");
            _PI_COPYREFERENCE.SetValue("REF_CUSTMR", "0010000003");

            IRfcStructure _PI_PERSONALDATA = _CUSTOMER.GetStructure("PI_PERSONALDATA");

            _PI_PERSONALDATA.SetValue("FIRSTNAME", "1234");
            _PI_PERSONALDATA.SetValue("LASTNAME", "DDDD");
            _PI_PERSONALDATA.SetValue("COUNTRY", "US");
            _PI_PERSONALDATA.SetValue("REGION", "AK");
            _PI_PERSONALDATA.SetValue("LANGU_P", "EN");
            _PI_PERSONALDATA.SetValue("CURRENCY", "USD");
            _PI_PERSONALDATA.SetValue("middlename", "john");
            _PI_PERSONALDATA.SetValue("date_birth", "19780101");
            _PI_PERSONALDATA.SetValue("langu_p", "EN");
            _PI_PERSONALDATA.SetValue("district", "Hyd");
            _PI_PERSONALDATA.SetValue("house_no", "11230");
            _PI_PERSONALDATA.SetValue("building", "super");
            _PI_PERSONALDATA.SetValue("room_no", "113");
            _PI_PERSONALDATA.SetValue("title_p", "Mr.");//Invalid form of address text error you need set Mr. reference table TSAD3T
            _PI_PERSONALDATA.SetValue("city", "LOS_ANGELES");
            //IRfcStructure _PI_OPT_PERSONALDATA = _CUSTOMER.GetStructure("PI_OPT_PERSONALDATA");
            //_PI_OPT_PERSONALDATA.SetValue("SHIP_COND", "01");
            //_PI_OPT_PERSONALDATA.SetValue("DELYG_PLNT", "1000");
            //IRfcFunction _SdCustomer = repo.CreateFunction("SD_CUSTOMER_MAINTAIN_ALL");
            //IRfcStructure _Knvv = _SdCustomer.GetStructure("I_KNVV");
            //_Knvv.SetValue("KUNNR", number);
            //_Knvv.SetValue("VKORG", "1000");
            //_Knvv.SetValue("VTWEG", "00");
            //_Knvv.SetValue("SPART", "00");
            //_Knvv.SetValue("KALKS", "1");
            //_Knvv.SetValue("BZIRK", "US");
            //_Knvv.SetValue("WAERS", "USD");
            //_Knvv.SetValue("KURST", "E");
            //_Knvv.SetValue("KONDA", "MSRP");
            //_Knvv.SetValue("VSBED", "01");
            //_Knvv.SetValue("INCO1", "DDP");
            //_Knvv.SetValue("INCO2", "US");
            RfcSessionManager.BeginContext(rfcDestination);
            _CUSTOMER.Invoke(rfcDestination);
            _Commit.Invoke(rfcDestination);
            RfcSessionManager.EndContext(rfcDestination);
            IRfcStructure   structReturn = _CUSTOMER.GetStructure("RETURN");
            string          _CUSTOMERNO  = _CUSTOMER.GetString("CUSTOMERNO");
            string          _TYPE        = structReturn.GetString("TYPE");
            string          _MESSAGE     = structReturn.GetString("MESSAGE");
            DataTable       dtReturn     = setErrorTable(_TYPE, _MESSAGE, "PI_COPYREFERENCE");
            List <ErrorLog> _ErrorList   = SetErrorLog(dtReturn, "BAPI_CUSTOMER_CREATEFROMDATA1", "", "");
            List <string>   _Error       = this._errorLogService.MiltiCreate(_ErrorList);

            return("");
        }