internal SDKBatch(SDK.QBSessionManager mgr, short majorVer, short minorVer, string Country) { _clousures = new Dictionary<int, ClosureSpec>(); _mgr = mgr; _msg = _mgr.CreateMsgSetRequest(Country, majorVer, minorVer); _iterator = null; if (_msg == null) throw new Exception("Can't create message set"); }
/// <summary> /// Closes this connection /// </summary> public void Close() { var sessionMgr = _sessionMgr; _sessionMgr = null; ConnectionMgr.ConnectionClosed(this); try { sessionMgr.EndSession(); sessionMgr.CloseConnection(); } catch (System.Runtime.InteropServices.COMException cex) { throw new SDKCloseException(cex); } }
internal SDKConnection(ConnectionMgr.ApplicationIdentity appID, ConnectionMgr.ConnectionConfig config) { _SDKMajorVersion = HOST_QUERY_QBXML_VERSION; _SDKMinorVersion = 0; SDK.ENConnectionType cnType; switch (config.ConnectionType) { case ConnectionMgr.FCConnectionType.Desktop: cnType = SDK.ENConnectionType.ctLocalQBD; break; case ConnectionMgr.FCConnectionType.DesktopLaunchUI: cnType = SDK.ENConnectionType.ctLocalQBDLaunchUI; break; case ConnectionMgr.FCConnectionType.Online: cnType = SDK.ENConnectionType.ctRemoteQBOE; _SDKMajorVersion = ONLINE_QBXML_VERSION; break; default: throw new Exception("Unsupported connection type:" + config.ConnectionType.ToString()); } try { var sessionMgr = new SDK.QBSessionManager(); sessionMgr.OpenConnection2(appID.IntuitAppID, appID.Name, cnType); _sessionMgr = sessionMgr; } catch (System.Runtime.InteropServices.COMException cex) { throw new SDKSessionException(cex); } _country = string.Empty; switch (appID.TargetEdition) { case ConnectionMgr.QBEdition.Australia: case ConnectionMgr.QBEdition.US: _country = "US"; break; case ConnectionMgr.QBEdition.Canada: _country = "CA"; break; case ConnectionMgr.QBEdition.UK: _country = "UK"; break; } SDK.ENOpenMode cnMode; if (config.RequireSingleUser) { cnMode = SDK.ENOpenMode.omSingleUser; } else { cnMode = SDK.ENOpenMode.omDontCare; } string filePath = config.FilePath; if (config.UseCurrentFile) filePath = string.Empty; try { _sessionMgr.BeginSession(filePath, cnMode); } catch(System.Runtime.InteropServices.COMException cex) { throw new SDKSessionException(cex); } }
public QBRequest DoInvoiceAdd(QBRequest wqObject) { bool sessionBegun = false; bool connectionOpen = false; //Create the session Manager object var sessionManager = new Interop.QBFC11.QBSessionManager(); try { IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest("US", wqObject.QBVersion, 0); //originally was 7 qbxml version supported # 1.1 March 2002 # 2.0 November 2002 # 2.1 June 2003 # 3.0 November 2003 # 4.0 November 2004 # 4.1 June 2005 # 5.0 November 2005 # 6.0 October 2006 requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue; try { using (var db = new PreferredFloristDBDataContext()) { customer = db.BC_BillingAddresses.FirstOrDefault(p => p.PF_accountNumber == wqObject.CustomerID); } } catch (Exception ex) { CatchHandler ch = new CatchHandler(); ch.CaptureError(ex); } BuildInvoiceAddRq(requestMsgSet, customer, wqObject); //Connect to QuickBooks and begin a session sessionManager.OpenConnection("", "Site Manager"); connectionOpen = true; try { sessionManager.BeginSession("", ENOpenMode.omMultiUser); } catch { sessionManager.BeginSession("", ENOpenMode.omSingleUser); } sessionBegun = true; //Send the request and get the response from QuickBooks IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet); //End the session and close the connection to QuickBooks sessionManager.EndSession(); sessionBegun = false; sessionManager.CloseConnection(); connectionOpen = false; WalkInvoiceAddRs(responseMsgSet); } catch (Exception ex) { if (sessionBegun) { sessionManager.EndSession(); } if (connectionOpen) { sessionManager.CloseConnection(); } qbTranasctionResponse = 99; qbTransactionResponseDetail = String.Format("AddInvoiceInQuickBooks failed. {0} {1}", ex.InnerException.Message, qbTransactionResponseDetail); CatchHandler ch = new CatchHandler(); ch.CaptureError(ex); } wqObject.QBListID = qbListIDforThisTransaction; wqObject.Status = qbTranasctionResponse; wqObject.StatusMessage = qbTransactionResponseDetail; return wqObject; }