Пример #1
0
        public static void Connect(dynamic diCompany)
        {
            if (IsConnected())
            {
                conn.Disconnect();
            }

            conn = diCompany as SAPbobsCOM.Company;
            k.Diagnostic.Debug(LOG, null, "SAP DI connected using ui api on {0} customer as {1}", conn.CompanyName, conn.UserName);
            LinkClient();
        }
Пример #2
0
    private int SetConnectionContext()
    {
        int setConnectionContextReturn = 0;

        string sCookie            = null;
        string sConnectionContext = null;
        int    lRetCode           = 0;

        // // First initialize the Company object

        oCompany = new SAPbobsCOM.Company();

        // // Acquire the connection context cookie from the DI API.
        sCookie = oCompany.GetContextCookie();

        // // Retrieve the connection context string from the UI API using the
        // // acquired cookie.
        sConnectionContext = SBO_Application.Company.GetConnectionContext(sCookie);

        // // before setting the SBO Login Context make sure the company is not
        // // connected

        if (oCompany.Connected == true)
        {
            oCompany.Disconnect();
        }

        // // Set the connection context information to the DI API.
        setConnectionContextReturn = oCompany.SetSboLoginContext(sConnectionContext);

        return(setConnectionContextReturn);
    }
Пример #3
0
 private void btnDisconnect_Click(object sender, EventArgs e)
 {
     try
     {
         if (oCompany.Connected == true)
         {
             oCompany.Disconnect();
             MessageBox.Show("You are now disconnected");
         }
         else
         {
             MessageBox.Show("You are not connected to the company.");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Exception: " + ex.Message);
     }
     finally
     {
         System.Runtime.InteropServices.Marshal.ReleaseComObject(oCompany);
         oCompany = null;
         Application.Exit();
     }
 }
 public static void FinalizeCompany()
 {
     if (oCompany.Connected == true)
     {
         oCompany.Disconnect();
     }
 }
        public static void InitializeCompany()
        {
            oCompany              = new SAPbobsCOM.Company();
            oCompany.Server       = ConfigurationManager.AppSettings["Server"];
            oCompany.language     = SAPbobsCOM.BoSuppLangs.ln_English;
            oCompany.UseTrusted   = false;
            oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_HANADB;
            oCompany.CompanyDB    = ConfigurationManager.AppSettings["CompanyDB"];
            oCompany.UserName     = ConfigurationManager.AppSettings["UserName"];
            oCompany.Password     = ConfigurationManager.AppSettings["UserPass"];
            oCompany.DbUserName   = ConfigurationManager.AppSettings["DbUserName"];
            oCompany.DbPassword   = ConfigurationManager.AppSettings["DbPassword"];

            if (oCompany.Connected == true)
            {
                oCompany.Disconnect();
            }

            long lRetCode = oCompany.Connect();

            if (lRetCode != 0)
            {
                int    temp_int    = 0;
                string temp_string = "";
                oCompany.GetLastError(out temp_int, out temp_string);

                Log.WriteLog("InitializeCompany Error: " + temp_string);
            }
        }
Пример #6
0
        private void TestConnection()
        {
            SAPbobsCOM.Company oCompany = new SAPbobsCOM.Company();
            ///Open the connection to sbo

            oCompany.Server        = ServerName;
            oCompany.LicenseServer = LicenseServer;
            oCompany.UserName      = UserName;
            oCompany.Password      = Password;
            oCompany.CompanyDB     = CompanyDB;
            oCompany.UseTrusted    = UseTrusted;
            if (!UseTrusted)
            {
                oCompany.DbUserName = DBUser;
                oCompany.DbPassword = DBPassword;
            }
            oCompany.DbServerType = dbServerType;


            int err = oCompany.Connect();

            if (err != 0)
            {
                sMessage = "Failed Connecting to SAP\n\r" + oCompany.GetLastErrorDescription();
            }
            else
            {
                sMessage = "Test connection successful";
                oCompany.Disconnect();
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(oCompany);
            GC.Collect();
        }
        public string ConectarBD()
        {
            oCompany              = new SAPbobsCOM.Company();
            oCompany.Server       = ConfigurationManager.AppSettings["Server"];
            oCompany.CompanyDB    = ConfigurationManager.AppSettings["Company"];
            oCompany.UserName     = ConfigurationManager.AppSettings["UserName"];
            oCompany.Password     = ConfigurationManager.AppSettings["Password"];
            oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2012;
            oCompany.DbUserName   = ConfigurationManager.AppSettings["DbUserName"];
            oCompany.DbPassword   = ConfigurationManager.AppSettings["DbPassword"];

            if (oCompany.Connected == true)
            {
                oCompany.Disconnect();
            }

            retVal = oCompany.Connect();
            if (retVal != 0)
            {
                string retStr = oCompany.GetLastErrorDescription();
                return("Error " + retVal + " " + retStr);
            }
            else
            {
                //return "Conectado a " + oCompany.CompanyName;
                return(InsertarRegistroInspeccion());
            }
        }
Пример #8
0
 public void Disconnect()
 {
     if (company != null)
     {
         company.Disconnect();
     }
 }
Пример #9
0
        public bool UpdateContactName(string bpCardCode, string ctnPrevName, string CtnNewName)

        {
            bool   bRetVal = false;
            string sErrMsg; int lErrCode;

            SAPbobsCOM.Company oCompany = new SAPbobsCOM.Company();
            oCompany = SAPDIAPI.Connect();

            //Check connection before updating

            if (oCompany.Connected)

            {
                //create the BP object

                SAPbobsCOM.BusinessPartners BP          = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners);
                SAPbobsCOM.ContactEmployees sboContacts = BP.ContactEmployees;

                try
                {
                    if (BP.GetByKey(bpCardCode))
                    {
                        sboContacts = BP.ContactEmployees;
                        //check first for one contact (always gives 1 wether have contact or not) check for no contact to add or update
                        if (sboContacts.Count > 0)
                        {
                            for (int i = 0; i < sboContacts.Count; i++)
                            {
                                sboContacts.SetCurrentLine(i);
                                if (sboContacts.Name == ctnPrevName)
                                {
                                    bRetVal          = true;
                                    sboContacts.Name = CtnNewName;
                                }
                            }
                        }
                        if (bRetVal)
                        {
                            if (BP.Update() != 0)
                            {
                                bRetVal = false;

                                oCompany.GetLastError(out lErrCode, out sErrMsg);
                            }
                        }
                    }
                }

                catch (Exception ex) { log.Error("Error number: " + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException); }

                {
                    bRetVal = false;
                }
            }

            oCompany.Disconnect();

            return(bRetVal);
        }
Пример #10
0
 static void Main(string[] args)
 {
     Console.WriteLine("Hello");
     try {
         SAPbobsCOM.Company company = new SAPbobsCOM.Company();
         company.CompanyDB     = "SBODemoUS";
         company.Server        = "MIKISURFACE";
         company.LicenseServer = "MIKISURFACE:30000";
         company.SLDServer     = "MIKISURFACE:40000";
         company.DbUserName    = "******";
         company.DbPassword    = "******";
         company.UseTrusted    = true;
         company.UserName      = "******";
         company.Password      = "******";
         company.DbServerType  = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2016;
         int    status    = company.Connect();
         string errorMsg  = company.GetLastErrorDescription();
         int    errorCode = company.GetLastErrorCode();
         System.Diagnostics.Debug.WriteLine($"Connection Status {status} msg {errorMsg} code {errorCode}");
         SAPbobsCOM.RecordsetEx rs = company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordsetEx);
         rs.DoQuery("select * from OITM");
         rs.MoveNext();
         string ic = rs.GetColumnValue("ItemCode");
         System.Diagnostics.Debug.WriteLine($"Item Code is {ic}");
         company.Disconnect();
         System.Diagnostics.Debug.WriteLine("Disconnected");
     } catch (Exception e) {
         System.Diagnostics.Debug.WriteLine(e.Message);
     }
 }
    //public static bool JEAllocation(string _Branch, string _PayrolPeriod)
    //{

    //    string sysDftDBCompany = "DESIHOFC";
    //    string sysDBUsername = ConfigurationManager.AppSettings["sysSAPUsername"];
    //    string sysDBPassword = ConfigurationManager.AppSettings["sysSAPPassword"];

    //    bool isConnected = false;
    //    string _Msg = "";
    //    oCompany = SAPInitializeConnection(sysDftDBCompany, sysDBUsername, sysDBPassword, out isConnected, out _Msg );
    //    MessageBox.Show(_Msg);
    //    if (isConnected == true)
    //    {

    //        string _sqlSelect;
    //        DataTable _tblSelect;

    //        _sqlSelect = @"
    //                                    SELECT A.Account, A.Credit, A.Debit, A.AccountName, A.EmployeeName, A.DocDate
    //                                    FROM [dbo].[fnSAPTransaction]('" + _Branch + @"','" + _PayrolPeriod + @"') A
    //                                ";
    //        _tblSelect = clsSQLClientFunctions.DataList(clsDeclaration.sSystemConnection, _sqlSelect);

    //        string _DocDate = clsSQLClientFunctions.GetData(_tblSelect, "DocDate", "0");


    //        SAPbobsCOM.JournalEntries _JournalEntries;
    //        _JournalEntries = (SAPbobsCOM.JournalEntries)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oJournalEntries);

    //        _JournalEntries.ReferenceDate = DateTime.Parse(_DocDate);
    //        _JournalEntries.TaxDate = DateTime.Parse(_DocDate);
    //        _JournalEntries.DueDate = DateTime.Parse(_DocDate);
    //        _JournalEntries.Memo = "PAYROLL PERIOD " + _PayrolPeriod + @" FOR " + _Branch;
    //        _JournalEntries.UserFields.Fields.Item("U_NSAPADVISENO").Value = _PayrolPeriod;


    //        foreach (DataRow row in _tblSelect.Rows)
    //        {
    //            {
    //                string _Account = row["Account"].ToString();
    //                string _Credit = row["Credit"].ToString();
    //                string _Debit = row["Debit"].ToString();
    //                string _AccountName = row["AccountName"].ToString();
    //                string _EmployeeName = row["EmployeeName"].ToString();

    //                if (_Account.Substring(0,1) == "V")
    //                {
    //                    _JournalEntries.Lines.ShortName = _Account;
    //                }
    //                else
    //                {
    //                    _JournalEntries.Lines.AccountCode = _Account;
    //                }

    //                _JournalEntries.Lines.LineMemo = _AccountName;

    //                _JournalEntries.Lines.Credit = double.Parse(_Credit);
    //                _JournalEntries.Lines.Debit = double.Parse(_Debit);
    //                _JournalEntries.Lines.UserFields.Fields.Item("U_NSAPADVISENO").Value = _PayrolPeriod;
    //                _JournalEntries.Lines.UserFields.Fields.Item("U_EMPLOYEE").Value = _EmployeeName;
    //                _JournalEntries.Lines.Add();
    //            }
    //        }


    //        int lRetCode;
    //        string sErrMsg;
    //        int lErrCode;
    //        Application.DoEvents();
    //        lRetCode = _JournalEntries.Add();

    //        if (lRetCode != 0)
    //        {
    //            oCompany.GetLastError(out lErrCode, out sErrMsg);
    //            MessageBox.Show(lErrCode + " " + sErrMsg);
    //            return false;
    //        }
    //        else
    //        {
    //            MessageBox.Show("Payroll Successfully Posted");
    //            return true;
    //        }

    //        oCompany.Disconnect();
    //    }
    //    else
    //    {
    //        return false;
    //    }



    //}



    public static void CreateIncomingPayment(string _Branch, string _PayrolPeriod, int _DocEntry
                                             , string _CardCode, string _CardName, string _CashAccount, double _Amount, DateTime _DocDate)
    {
        string sysDftDBCompany = "DESIHOFC";
        string sysDBUsername   = ConfigurationManager.AppSettings["sysSAPUsername"];
        string sysDBPassword   = ConfigurationManager.AppSettings["sysSAPPassword"];

        bool   isConnected = false;
        string _Msg        = "";

        oCompany = SAPInitializeConnection(sysDftDBCompany, sysDBUsername, sysDBPassword, out isConnected, out _Msg);
        //MessageBox.Show(_Msg);

        if (isConnected == true)
        {
            SAPbobsCOM.Payments _Payments;
            _Payments = (SAPbobsCOM.Payments)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oIncomingPayments);


            _Payments.CardCode       = _CardCode;
            _Payments.CardName       = _CardName;
            _Payments.CashAccount    = _CashAccount;
            _Payments.CashSum        = _Amount;
            _Payments.DocDate        = _DocDate;
            _Payments.JournalRemarks = "Integra Console " + _PayrolPeriod + @" Branch : " + _Branch;
            _Payments.TaxDate        = _DocDate;


            _Payments.Invoices.DocEntry    = _DocEntry;
            _Payments.Invoices.DocLine     = 0;
            _Payments.Invoices.InvoiceType = SAPbobsCOM.BoRcptInvTypes.it_Invoice;
            _Payments.Invoices.SumApplied  = _Amount;


            int    lRetCode;
            string sErrMsg;
            int    lErrCode;
            Application.DoEvents();
            lRetCode = _Payments.Add();

            if (lRetCode != 0)
            {
                oCompany.GetLastError(out lErrCode, out sErrMsg);
                //MessageBox.Show(lErrCode + " " + sErrMsg);
            }
            else
            {
                //MessageBox.Show("Payroll Successfully Posted");
            }

            oCompany.Disconnect();
        }
        else
        {
            MessageBox.Show(_Msg);
        }
    }
Пример #12
0
 private void Form_CloseBefore(SAPbouiCOM.SBOItemEventArg pVal, out bool BubbleEvent)
 {
     BubbleEvent = true;
     try
     {
         oCompany.Disconnect();
     }
     catch
     { }
 }
Пример #13
0
        void application_AppEvent(SAPbouiCOM.BoAppEventTypes EventType)
        {
            switch (EventType)
            {
            case SAPbouiCOM.BoAppEventTypes.aet_CompanyChanged:
                company.Disconnect();
                Environment.Exit(0);
                break;

            case SAPbouiCOM.BoAppEventTypes.aet_ServerTerminition:
                company.Disconnect();
                Environment.Exit(0);
                break;

            case SAPbouiCOM.BoAppEventTypes.aet_ShutDown:
                company.Disconnect();
                Environment.Exit(0);
                break;
            }
        }
Пример #14
0
 public void proDesconectarBDSap()
 {
     try
     {
         if (objConexionSap.Connected)
         {
             objConexionSap.Disconnect();
         }
     }
     catch (Exception) { throw; }
 }
Пример #15
0
 private void Form_CloseBefore(SAPbouiCOM.SBOItemEventArg pVal, out bool BubbleEvent)
 {
     BubbleEvent = true;
     try
     {
         oCompany.Disconnect();
     }
     catch
     { }
     //throw new System.NotImplementedException();
 }
Пример #16
0
 /// <summary>
 /// Metodo para desconeconectar la compañia de la instacia de SBO que se esta ejecutando (DIAPI)
 /// </summary>
 public static void DesconectarCompany()
 {
     try
     {
         m_oCompany.Disconnect();
     }
     catch (Exception ex)
     {
         Comunes.Msj_Appl.Errores(6, ex.Message);
     }
 }
Пример #17
0
 void Disconnect()
 {
     if (_company != null)
     {
         if (_company.Connected)
         {
             _company.Disconnect();
         }
         _company = null;
         System.Diagnostics.Debug.WriteLine("SAP DI is disconnected");
     }
 }
Пример #18
0
 private void butDITest_Click(object sender, EventArgs e)
 {
     try
     {
         SAPbobsCOM.Company b1Company = CompanyConnectTest();
         MessageBox.Show(string.Format("成功连接至账套[{0}/{1}]", b1Company.CompanyDB, b1Company.CompanyName));
         b1Company.Disconnect();
         System.Runtime.InteropServices.Marshal.FinalReleaseComObject(b1Company);
     }
     catch (Exception error)
     {
         MessageBox.Show(error.Message);
     }
 }
Пример #19
0
        /// <summary>
        /// Handle App Event
        /// </summary>
        public void HandleAppEvent(SAPbouiCOM.BoAppEventTypes EventType)
        {
            switch (EventType)
            {
            case SAPbouiCOM.BoAppEventTypes.aet_ShutDown:
                if (oSBOCompany.Connected)
                {
                    oSBOCompany.Disconnect();
                }
                System.Windows.Forms.Application.Exit();
                break;

            case SAPbouiCOM.BoAppEventTypes.aet_CompanyChanged:
                if (oSBOCompany.Connected)
                {
                    oSBOCompany.Disconnect();
                }
                System.Windows.Forms.Application.Exit();
                break;

            case SAPbouiCOM.BoAppEventTypes.aet_LanguageChanged:
                if (oSBOCompany.Connected)
                {
                    oSBOCompany.Disconnect();
                }
                System.Windows.Forms.Application.Exit();
                break;

            case SAPbouiCOM.BoAppEventTypes.aet_ServerTerminition:
                if (oSBOCompany.Connected)
                {
                    oSBOCompany.Disconnect();
                }
                System.Windows.Forms.Application.Exit();
                break;
            }
        }
        public static SAPbobsCOM.Company InitializeCompany()
        {
            try
            {
                //Log.WriteLog("Inicializando conexão com o BD e SAP.");

                oCompany = new SAPbobsCOM.Company
                {
                    Server       = ConfigurationManager.AppSettings["Server"],
                    language     = SAPbobsCOM.BoSuppLangs.ln_English,
                    UseTrusted   = false,
                    DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2016,
                    CompanyDB    = ConfigurationManager.AppSettings["DataBase"],
                    UserName     = ConfigurationManager.AppSettings["SapUser"],
                    Password     = ConfigurationManager.AppSettings["SapPassword"],
                    DbUserName   = ConfigurationManager.AppSettings["DbUser"],
                    DbPassword   = ConfigurationManager.AppSettings["DbPassword"],
                    //LicenseServer = "sapsrv:30000"
                };

                if (oCompany.Connected == true)
                {
                    oCompany.Disconnect();
                }

                long lRetCode = oCompany.Connect();

                if (lRetCode != 0)
                {
                    int    temp_int    = 0;
                    string temp_string = "";
                    oCompany.GetLastError(out temp_int, out temp_string);

                    //Log.WriteLog("InitializeCompany Error: " + temp_string);
                    return(oCompany);
                }
                else
                {
                    //Log.WriteLog("Conexão realizada com sucesso.");
                    return(oCompany);
                    //Inserir na tabela de log
                }
            }
            catch (System.Exception e)
            {
                //Log.WriteLog("InitializeCompany Exception: "+e.Message);
                throw e;
            }
        }
Пример #21
0
 public void Connecting(out string message)
 {
     message = string.Empty;
     if (company.Connected)
     {
         company.Disconnect();
     }
     if (!company.Connected)
     {
         if (company.Connect() != 0)
         {
             message = company.GetLastErrorDescription();
         }
     }
 }
Пример #22
0
 private static void Disconnect()
 {
     try
     {
         if (_diCompany.Connected)
         {
             _diCompany.Disconnect();
         }
     }
     finally
     {
         _diCompany   = null;
         _application = null;
     }
 }
Пример #23
0
        public void salirAddon()
        {
            try
            {
                if (oCompany.Connected == true)
                {
                    oCompany.Disconnect();
                }

                System.Windows.Forms.Application.Exit();
            }
            catch (Exception ex)
            {
                System.Windows.Forms.Application.Exit();
            }
        }
Пример #24
0
        /// <summary>
        /// Termina el proceso del Addon.
        /// </summary>
        public void salirAddon()
        {
            try
            {
                if (oCompany.Connected == true)
                {
                    oCompany.Disconnect();
                }

                System.Windows.Forms.Application.Exit();
            }
            catch (Exception ex)
            {
                SBO_Application.MessageBox("Addon término su proceso - " + ex.Message);
                System.Windows.Forms.Application.Exit();
            }
        }
Пример #25
0
        public string execRinnovo()
        {
            string _q = @"select ""CardCode"", ""DocEntry"", ""U_Perc_Fat1"", ""U_Imp_Fat1"", ""GrosProfit"", ""DocTotal"", ""VatSum""
                             from ""ORDR"" where ""DocStatus"" = 'O' and  ""Confirmed"" = 'Y' and(""U_Stato_Fat1"" = 0 or ""U_Stato_Fat1"" = 2)
                             and ""U_Data_Fat1"" <= '2017-01-31'; ";

            SAPbobsCOM.Recordset oRecordSet;
            oRecordSet = (SAPbobsCOM.Recordset)c.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);


            oRecordSet.DoQuery(_q);


            Console.WriteLine(oRecordSet.RecordCount);

            c.Disconnect();


            return("");
        }
Пример #26
0
 private void butDITest_Click(object sender, EventArgs e)
 {
     try
     {
         this.butDITest.Text      = "正在尝试连接DI,请稍候...";
         this.ButtonsVisibleStyle = this.ButtonsVisibleStyle | UI.ButtonsVisibleStyle.NextDisable;
         Application.DoEvents();
         SAPbobsCOM.Company b1Company = CompanyConnectTest();
         MessageBox.Show(string.Format("成功连接至账套[{0}/{1}]", b1Company.CompanyDB, b1Company.CompanyName));
         this.ConnectDiSucess = true;
         b1Company.Disconnect();
         System.Runtime.InteropServices.Marshal.FinalReleaseComObject(b1Company);
     }
     catch (Exception error)
     {
         this.ConnectDiSucess = false;
         MessageBox.Show(error.Message);
     }
     this.ButtonsVisibleStyle = this.ButtonsVisibleStyle ^ UI.ButtonsVisibleStyle.NextDisable;
     this.butDITest.Text      = "测试DI连接";
 }
Пример #27
0
        private int SetConnectionContext()
        {
            int setConnectionContextReturn = 0;

            string sCookie = null;
            string sConnectionContext = null;
            int lRetCode = 0;

            oCompany = new SAPbobsCOM.Company();

            sCookie = oCompany.GetContextCookie();
            sConnectionContext = SBO_Application.Company.GetConnectionContext(sCookie);

            if (oCompany.Connected == true)
            {
                oCompany.Disconnect();
            }
            setConnectionContextReturn = oCompany.SetSboLoginContext(sConnectionContext);

            return setConnectionContextReturn;
        }
Пример #28
0
        static void Main(string[] args)
        {
            try
            {
                DateTime fechaSap = DateTime.Now.AddDays(1);
                WebServiceTRMReference.TCRMServicesInterfaceClient ws = new WebServiceTRMReference.TCRMServicesInterfaceClient();
                WebServiceTRMReference.tcrmResponse respuestaTRM      = new WebServiceTRMReference.tcrmResponse();
                respuestaTRM = ws.queryTCRM(fechaSap);

                SAPbobsCOM.Company oCompany = new SAPbobsCOM.Company();
                oCompany.Server        = ConfigurationManager.AppSettings.Get("Server");
                oCompany.LicenseServer = ConfigurationManager.AppSettings.Get("LicenseServer");
                oCompany.CompanyDB     = ConfigurationManager.AppSettings.Get("CompanyDB");
                oCompany.UserName      = ConfigurationManager.AppSettings.Get("UserName");
                oCompany.Password      = ConfigurationManager.AppSettings.Get("Password");

                switch (ConfigurationManager.AppSettings.Get("DbServerType"))
                {
                case "dst_HANADB":
                    oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_HANADB;
                    break;

                case "dst_MSSQL2005":
                    oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2005;
                    break;

                case "dst_MSSQL2008":
                    oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2008;
                    break;

                case "dst_MSSQL2012":
                    oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2012;
                    break;

                case "dst_MSSQL2014":
                    oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2014;
                    break;

                case "dst_MSSQL2016":
                    oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2016;
                    break;
                }



                int resultado = oCompany.Connect();
                if (resultado == 0)
                {
                    SAPbobsCOM.SBObob bo = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoBridge);
                    bo.SetCurrencyRate("USD", fechaSap, Math.Round(respuestaTRM.value, 2), true);

                    oCompany.Disconnect();

                    Console.WriteLine("TRM Actualizada!");
                    string asunto  = "TRM SAP " + ConfigurationManager.AppSettings.Get("CompanyDB") + " Actualizada " + fechaSap.ToString().Substring(0, 10);
                    string mensaje = "Se ha realizado correctamente la actualizacion de la tasa de cambio del dolar para el dia " + fechaSap.ToString().Substring(0, 10) + " - TRM: $" + respuestaTRM.value;
                    //envia el correo solo en caso de existir error de actualizacion
                    if (ConfigurationManager.AppSettings.Get("CorreoErrorActualiza") == "NO")
                    {
                        EnviarCorreo(asunto, mensaje);
                    }
                    Environment.Exit(1);
                }
                else
                {
                    throw new Exception(oCompany.GetLastErrorCode() + ": " + oCompany.GetLastErrorDescription());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
                string asunto  = "TRM SAP " + ConfigurationManager.AppSettings.Get("CompanyDB") + " *ERROR* " + DateTime.Now.AddDays(1);
                string mensaje = "Error en la actualizacion: " + DateTime.Now.AddDays(1) + " **" + ex.Message;
                EnviarCorreo(asunto, mensaje);
            }
        }
Пример #29
0
        static void Main(string[] args)
        {
            Console.WriteLine("Izmjena kursne liste u toku. Molim sačekajte....");

            SAPbobsCOM.Company   company;
            SAPbobsCOM.SBObob    sBObob;
            SAPbobsCOM.Recordset recordset;

            company = new SAPbobsCOM.Company();

            company.Server        = "SapServer";
            company.DbServerType  = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2014;
            company.CompanyDB     = "SapDb";
            company.LicenseServer = "SapServer:30000";
            company.UserName      = "******";
            company.Password      = "******";

            int result = company.Connect();

            string err = company.GetLastErrorDescription();

            DateTime danas = DateTime.Now;

            //DateTime danas = new DateTime(2018, 8, 19);

            string uri = "https://www.cbbh.ba/CurrencyExchange/GetXml?date=" + danas.Month.ToString() + " " + danas.Day.ToString() + " " + danas.Year.ToString();

            XDocument xDocument = XDocument.Load(uri);

            var tagovi = xDocument.Descendants("CurrencyExchangeItem")
                         .Where(x => x.Elements("AlphaCode") != null && x.Elements("Middle") != null)
                         .Select(x => new
            {
                Valuta  = x.Element("AlphaCode").Value,
                Srednji = x.Element("Middle").Value
            });


            sBObob = (SAPbobsCOM.SBObob)company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoBridge);

            recordset = (SAPbobsCOM.Recordset)company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);

            //recordset = sBObob.GetLocalCurrency();
            //recordset = sBObob.GetSystemCurrency();

            foreach (var tag in tagovi)
            {
                if (tag.Valuta.ToString() == "USD")
                {
                    sBObob.SetCurrencyRate("$", DateTime.Now, Convert.ToDouble(tag.Srednji), true);
                }

                if (tag.Valuta.ToString() == "CHF")
                {
                    sBObob.SetCurrencyRate("CHF", DateTime.Now, Convert.ToDouble(tag.Srednji), true);
                }

                if (tag.Valuta.ToString() == "GBP")
                {
                    sBObob.SetCurrencyRate("GBP", DateTime.Now, Convert.ToDouble(tag.Srednji), true);
                }

                if (tag.Valuta.ToString() == "EUR")
                {
                    sBObob.SetCurrencyRate("EUR", DateTime.Now, Convert.ToDouble(tag.Srednji), true);
                }
            }

            company.Disconnect();

            Marshal.FinalReleaseComObject(company);

            Console.WriteLine("Izmjena kursne liste završena!");
            Console.WriteLine("Izlazim iz programa....");
        }
Пример #30
0
        public static void GenearLeadSAP2(string agente, string solicitud, string codigoAsistente, string nombreAsistente, int dia, int mes, int year, string telefono, string nombre, string apellidoP, string apellidoM,
                                          string direccion, string entreCalles, string municipio, string colonia, string observaciones, string nvoIngreso, string codigoPostal, string rfc, string esquema,
                                          ref string msgError, ref string CodigoActivacion)
        {
            SAPbobsCOM.BusinessPartners oSocioNegocio = null;
            string cardCodeGenerate = null;
            string nombreCompleto   = null;

            Conexiones.ConexionSAP _oConnection = new Conexiones.ConexionSAP();
            try
            {
                _oConnection = new Conexiones.ConexionSAP();
                if (_oConnection.ConectarSAP(ref msgError))
                {
                    oCompany = _oConnection._oCompany;
                    oCompany.StartTransaction();
                    nombreCompleto = nombre.TrimEnd(' ') + ' ' + apellidoP.TrimEnd(' ') + ' ' + apellidoM.TrimEnd(' ');
                    oSocioNegocio  = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners);
                    ObtenerDatosSolicitudValidacion(solicitud);
                    oSocioNegocio.Series         = DatosSolicitud.ElementAt(0).serieLead;
                    oSocioNegocio.CardType       = SAPbobsCOM.BoCardTypes.cLid;
                    oSocioNegocio.GroupCode      = ObtenerGrupoLead();
                    oSocioNegocio.CardName       = nombreCompleto;
                    oSocioNegocio.FederalTaxID   = rfc;
                    oSocioNegocio.DebitorAccount = Extensor.Configuracion.VENTANA.CuentaLead;
                    oSocioNegocio.UserFields.Fields.Item("U_QCapturaContrato").Value = agente;
                    oSocioNegocio.UserFields.Fields.Item("U_SolicitudInt").Value     = solicitud;
                    oSocioNegocio.UserFields.Fields.Item("U_CodigoPromotor").Value   = codigoAsistente;
                    oSocioNegocio.UserFields.Fields.Item("U_NomProm").Value          = nombreAsistente;
                    oSocioNegocio.UserFields.Fields.Item("U_Dia").Value  = dia.ToString();
                    oSocioNegocio.UserFields.Fields.Item("U_Mes").Value  = mes.ToString();
                    oSocioNegocio.UserFields.Fields.Item("U_Year").Value = year.ToString();
                    oSocioNegocio.UserFields.Fields.Item("U_ComentarioContrato").Value = observaciones;
                    oSocioNegocio.UserFields.Fields.Item("U_PersonaNvoIngreso").Value  = nvoIngreso;
                    oSocioNegocio.UserFields.Fields.Item("U_NumArt_").Value            = DatosSolicitud.ElementAt(0).plan;
                    oSocioNegocio.UserFields.Fields.Item("U_Dsciption").Value          = DatosSolicitud.ElementAt(0).nombrePlan;
                    oSocioNegocio.UserFields.Fields.Item("U_PrefijoPlan").Value        = DatosSolicitud.ElementAt(0).prefijoPlan;
                    oSocioNegocio.UserFields.Fields.Item("U_FechaCaptura").Value       = DateTime.Now.ToShortDateString();
                    oSocioNegocio.UserFields.Fields.Item("U_HoraCaptura").Value        = DateTime.Now.ToString("HH:mm:ss");
                    oSocioNegocio.UserFields.Fields.Item("U_Esquema_pago").Value       = esquema;

                    if (nombreCompleto.Length > 70)
                    {
                        oSocioNegocio.UserFields.Fields.Item("U_BeneficiarioPagoRe").Value = nombreCompleto.ToString().Substring(1, 70);
                    }
                    else
                    {
                        oSocioNegocio.UserFields.Fields.Item("U_BeneficiarioPagoRe").Value = nombreCompleto;
                    }
                    oSocioNegocio.Addresses.AddressType       = SAPbobsCOM.BoAddressType.bo_BillTo;
                    oSocioNegocio.Addresses.AddressName       = "DIRECCION 1";
                    oSocioNegocio.Addresses.AddressName2      = telefono;
                    oSocioNegocio.Addresses.Street            = direccion;
                    oSocioNegocio.Addresses.BuildingFloorRoom = entreCalles;
                    oSocioNegocio.Addresses.City    = municipio;
                    oSocioNegocio.Addresses.Block   = colonia;
                    oSocioNegocio.Addresses.ZipCode = codigoPostal;
                    oSocioNegocio.Addresses.State   = "JAL";

                    if (oSocioNegocio.Add() != 0)
                    {
                        msgError = "Error: " + oCompany.GetLastErrorDescription();
                    }
                    else
                    {
                        //oCompany.GetNewObjectCode(out cardCodeGenerate);
                        msgError = "";
                    }
                }
                else
                {
                    msgError = "Error: " + msgError;
                }
            }
            catch (Exception ex)
            {
                msgError = "Error: " + msgError + " : " + ex.Message;
            }
            finally
            {
                if (!msgError.Contains("Error"))
                {
                    oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
                    //CodigoActivacion = ObtenerCodigoActivacionGenerado(cardCodeGenerate);
                    //msgError = "El código de activación es: " + CodigoActivacion;
                }
                else
                {
                    oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                }
                if (oSocioNegocio != null)
                {
                    GC.SuppressFinalize(oSocioNegocio);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oSocioNegocio);
                    oSocioNegocio = null;
                }
                GC.Collect();
                ClearMemory();
                oCompany.Disconnect();
            }
        }
Пример #31
0
        public SAPbobsCOM.Company ConnectToTargetCompany(SAPbobsCOM.Company oCompany, string sUserName, string sPassword, string sDBName,
                                                         string sServer, string sLicServerName, string sDBUserName
                                                         , string sDBPassword, string sErrDesc)
        {
            string sFuncName = string.Empty;
            //SAPbobsCOM.Company oCompany = new SAPbobsCOM.Company();
            long lRetCode;

            try
            {
                sFuncName = "ConnectToTargetCompany()";

                if (p_iDebugMode == DEBUG_ON)
                {
                    oLog.WriteToDebugLogFile("Starting Function ", sFuncName);
                }

                if (oCompany != null)
                {
                    if (p_iDebugMode == DEBUG_ON)
                    {
                        oLog.WriteToDebugLogFile("Disconnecting the Company object - Company Name " + oCompany.CompanyName, sFuncName);
                    }
                    oCompany.Disconnect();
                }
                oCompany = new SAPbobsCOM.Company();
                if (p_iDebugMode == DEBUG_ON)
                {
                    oLog.WriteToDebugLogFile("After Initializing Company Connection ", sFuncName);
                }
                oCompany.Server        = sServer;
                oCompany.LicenseServer = sLicServerName;
                oCompany.DbUserName    = sDBUserName;
                oCompany.DbPassword    = sDBPassword;
                oCompany.language      = SAPbobsCOM.BoSuppLangs.ln_English;
                oCompany.UseTrusted    = false;
                oCompany.DbServerType  = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2012;


                oCompany.CompanyDB = sDBName;// sDataBaseName;
                oCompany.UserName  = sUserName;
                oCompany.Password  = sPassword;

                if (p_iDebugMode == DEBUG_ON)
                {
                    oLog.WriteToDebugLogFile("Connecting the Database...", sFuncName);
                }

                lRetCode = oCompany.Connect();

                if (lRetCode != 0)
                {
                    throw new ArgumentException(oCompany.GetLastErrorDescription());
                }
                else
                {
                    if (p_iDebugMode == DEBUG_ON)
                    {
                        oLog.WriteToDebugLogFile("Company Connection Established", sFuncName);
                    }
                    if (p_iDebugMode == DEBUG_ON)
                    {
                        oLog.WriteToDebugLogFile("Completed With SUCCESS", sFuncName);
                    }
                    return(oCompany);
                }
            }
            catch (Exception Ex)
            {
                sErrDesc = Ex.Message.ToString();
                if (p_iDebugMode == DEBUG_ON)
                {
                    oLog.WriteToErrorLogFile(sErrDesc, sFuncName);
                }
                if (p_iDebugMode == DEBUG_ON)
                {
                    oLog.WriteToDebugLogFile("Completed With ERROR  ", sFuncName);
                }
                throw Ex;
            }
        }