Beispiel #1
0
        private async Task <bool> connectToQB()
        {
            try
            {
                rp = new RequestProcessor2(); //RequestProcessor2(); //RequestProcessor2Class();
                await Task.Run(() => rp.OpenConnection(appID, appName));

                ticket = rp.BeginSession(companyFile, mode);
                string[] versions = (string[])rp.get_QBXMLVersionsForSession(ticket);//Array.ConvertAll<System.Array, string>(rp.get_QBXMLVersionsForSession(ticket),Convert.ToString);
                maxVersion = versions[versions.Length - 1];
                return(true);
            }
            catch (Exception ex)
            {
                ErrorList.Add(DateTime.Now, ex);
                return(false);
            }
        }
Beispiel #2
0
 // CONNECTION TO QB
 private void ConnectToQB()
 {
     if (rp == null)
     {
         try
         {
             rp = new RequestProcessor2Class();
             rp.OpenConnection2(AppID, AppName, QBXMLRPConnectionType.localQBD);
             if (CompanyFile == null)
             {
                 CompanyFile = string.Empty;
             }
             ticket = rp.BeginSession(CompanyFile, mode);
             string[] versions = (string[])rp.get_QBXMLVersionsForSession(ticket);
             MaxVersion = versions[versions.Length - 1];
         }
         catch (Exception e)
         {
             Logger.LogException(e);
             DisconnectFromQB();
         }
     }
 }
Beispiel #3
0
        public bool Connect()
        {
            if (Config.IsProduction == false)
            {
                return(true);
            }

            if (localhost == true)
            {
                return(true);
            }

            if (ticket != string.Empty)
            {
                return(true);
            }
            try
            {
                rp = new RequestProcessor2();
                rp.OpenConnection("", appName);
                ticket = rp.BeginSession(fileName, QBFileMode.qbFileOpenDoNotCare);
                if (ticket != string.Empty)
                {
                    string[] versions = rp.get_QBXMLVersionsForSession(ticket);
                    maxVersion = versions[versions.Length - 1];
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error al conectar a Quickbooks: " + ex.Message);
            }
            return(true);
        }
Beispiel #4
0
        //if connection esists or established, return true; else return false
        public bool ConnectToQB()
        {
            if (m_ticket == null)
            {
                rp = new RequestProcessor2Class();
                rp.OpenConnection(m_appID, m_appName);

                for (int i = 0; i < m_maxIterations; i++ )
                {
                    try
                    {
                        m_ticket = rp.BeginSession("", QBFileMode.qbFileOpenDoNotCare);
                    }
                    catch (System.Runtime.InteropServices.COMException ex)
                    {
                        LogHelper.Error(ex);
                        if (ex.ErrorCode == ERROR_CODE_MODAL_DIALOG)
                        {
                            int isClosed = WindowOperation.CloseModalDialog("qbw32");
                            //if (isClosed != WindowOperation.NOTCLOSED)
                            //{
                            //m_ticket = rp.BeginSession("", QBFileMode.qbFileOpenDoNotCare);
                            //}
                        }
                        //return "<QBStatus>" + ex.Message + "</Q>";
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Error(ex);
                    }
                    finally
                    {
                        if (m_ticket != null)
                        {
                            m_versions = rp.get_QBXMLVersionsForSession(m_ticket);
                            m_maxVersion = m_versions[m_versions.Length - 1];
                        }
                    }

                    if (m_ticket != null)
                        return true;
                }
                return false;
            }
            //return "ConnectToQB: Max Version:" + m_maxVersion;
            return true;
        }
Beispiel #5
0
        //THIS IS INVALUABLE
        //https://developer-static.intuit.com/qbSDK-current/Common/newOSR/index.html


        /*ALSO THIS NEEDS TO BE LOOKED AT AT SOME POINT - This is how we will map autofile records with Reckon invoices and bills for updating and adding new items to exisintg bills
         *
         * defMacro
         * Note that defMacro was introduced with SDK 2.0, so it only works with 2.0 and higher requests. You can use the defMacro attribute to assign a name to the TxnID or TxnListID that this aggregate will return. This way you can refer to the transaction by name in a later request. For example, if you were using the qbXML API and you defined an invoice add request with the name TxnID:RecvPmt1234, as shown below, then you could refer to that invoice by name in a later receive payment add request:
         *
         * <InvoiceAddRq>
         * <InvoiceAdd defMacro= "TxnID:RecvPmt1234">
         * . . .
         * <ReceivePaymentAddRq>
         * <ReceivePaymentAdd>
         * . . .
         * <TxnID useMacro="TxnID:RecvPmt1234"/>
         * . . .
         *
         * If you use macros with QBOE...
         * There may be a buug in the QBOE implementation of this feature. If this feature is not working for you in QBOE, try stripping the prefix "TxnID:" from the name of the useMacro. For example, defMacro="TxnID:RecvPmt1234" and useMacro="RecvPmt1234"
         */



        public bool connectToQB(string companyFile)
        {
            //int authflags = 0;
            //authflags = authflags | 0x01;



            //int authFlags = 0x1 - 0x2 - 0x4;

            //var qbXMLCOM = new RequestProcessor2();
            //var prefs = new AuthPreferences();
            //prefs = qbXMLCOM.AuthPreferences as AuthPreferences;
            //prefs.PutAuthFlags(authFlags);

            //qbXMLCOM.OpenConnection(appID, appName);

            //ticket = qbXMLCOM.BeginSession(companyFile, mode);
            //var versions = qbXMLCOM.get_QBXMLVersionsForSession(ticket);
            //maxVersion = versions.GetValue(versions.Length - 1).ToString();
            //return true;


            //Dim authFlags As Long
            //authFlags = 0
            //authFlags = authFlags Or & H8 &
            //authFlags = authFlags Or & H4 &
            //authFlags = authFlags Or & H2 &
            //authFlags = authFlags Or & H1 &
            //authFlags = authFlags Or & H80000000
            //Dim qbXMLCOM As QBXMLRP2Lib.RequestProcessor2
            //Dim prefs As QBXMLRP2Lib.AuthPreferences
            //Set prefs = qbXMLCOM.AuthPreferences
            //prefs.PutAuthFlags(authFlags)
            int authFlags = 0;

            authFlags = 0;
            authFlags = (int)(authFlags | 0x8L);
            authFlags = (int)(authFlags | 0x4L);
            authFlags = (int)(authFlags | 0x2L);
            authFlags = (int)(authFlags | 0x1L);
//            int authFlags = 0x1 - 0x2 - 0x4;
            //var rp = new RequestProcessor2();
            var prefs = (AuthPreferences)rp.AuthPreferences;  //new AuthPreferences();

//            prefs = (AuthPreferences)qbXMLCOM.AuthPreferences;
            prefs.PutAuthFlags(authFlags);
            try
            {
                rp.OpenConnection(appID, appName);
                ticket = rp.BeginSession(companyFile, mode);
                var versions = rp.get_QBXMLVersionsForSession(ticket);
                maxVersion = versions.GetValue(versions.Length - 1).ToString();
            }
            catch (Exception Ex)
            {
                if (Ex.Message != null && Ex.Message == "Could not start Reckon Accounts.")
                {
                    MessageBox.Show("Error: " + Ex.Message + Environment.NewLine + Environment.NewLine + "Please ensure you have Reckon running and the company file you wish to integrate open.");
                }
                else
                {
                    MessageBox.Show("Error: " + Ex.Message);
                }
                rp.CloseConnection();
                return(false);
            }
            return(true);
        }