public static void Show() { Console.WriteLine("Chart of Accounts from the current company file"); using (var cn = ConnectionMgr.GetConnection()) { var batch = cn.NewBatch(); var qry = batch.MsgSet.AppendAccountQueryRq(); //if return elements are not specified, the account query can trigger permission errors //because bank and credit card account numbers are included by default qry.IncludeRetElementList.Add("Name"); qry.IncludeRetElementList.Add("AccountType"); batch.SetClosures(qry, b => { var accounts = new QBFCIterator <IAccountRetList, IAccountRet>(b); foreach (var account in accounts) { Console.WriteLine(" Account name:{0}, type {1}", Safe.Value(account.Name), account.AccountType.GetAsString()); } }); batch.Run(); } }
public static void Show() { Console.WriteLine("Chart of Accounts from the current company file"); using (var cn = ConnectionMgr.GetConnection()) { var batch = cn.NewBatch(); var qry = batch.MsgSet.AppendAccountQueryRq(); //if return elements are not specified, the account query can trigger permission errors //because bank and credit card account numbers are included by default qry.IncludeRetElementList.Add("Name"); qry.IncludeRetElementList.Add("AccountType"); batch.SetClosures(qry, b => { var accounts = new QBFCIterator<IAccountRetList, IAccountRet>(b); foreach (var account in accounts) { Console.WriteLine(" Account name:{0}, type {1}", Safe.Value(account.Name), account.AccountType.GetAsString()); } }); batch.Run(); } }
public static void Run() { using (var cn = ConnectionMgr.GetConnection()) { Console.WriteLine("WARNING: this demonstration will change the name of every customer in your company file. Are you sure you want to do this? (y/n)"); switch (Console.ReadKey().KeyChar) { case 'y': case 'Y': break; default: return; } var queryBatch = cn.NewBatch(); var updateBatch = cn.NewBatch(); var qry = queryBatch.MsgSet.AppendCustomerQueryRq(); //specify returned values to limit the size of the XML qry.IncludeRetElementList.Add("ListID"); qry.IncludeRetElementList.Add("EditSequence"); qry.IncludeRetElementList.Add("CompanyName"); queryBatch.SetClosures(qry, b => { var customers = new QBFCIterator <ICustomerRetList, ICustomerRet>(b); foreach (var customer in customers) { var qryMod = updateBatch.MsgSet.AppendCustomerModRq(); qryMod.ListID.SetValue(Safe.Value(customer.ListID)); qryMod.EditSequence.SetValue(Safe.Value(customer.EditSequence)); string tweakedName = Safe.Value(customer.CompanyName) + " tweaked by Zombie"; qryMod.CompanyName.SetValue(Safe.LimitedString(tweakedName, 41)); } }); StatusMgr.Trace("Running query for all edit sequences"); if (!queryBatch.Run()) { return; } StatusMgr.Trace("Updating all customers"); updateBatch.Run(); } }
public static void Run() { using (var cn = ConnectionMgr.GetConnection()) { Console.WriteLine("WARNING: this demonstration will change the name of every customer in your company file. Are you sure you want to do this? (y/n)"); switch (Console.ReadKey().KeyChar) { case 'y': case 'Y': break; default: return; } var queryBatch = cn.NewBatch(); var updateBatch = cn.NewBatch(); var qry = queryBatch.MsgSet.AppendCustomerQueryRq(); //specify returned values to limit the size of the XML qry.IncludeRetElementList.Add("ListID"); qry.IncludeRetElementList.Add("EditSequence"); qry.IncludeRetElementList.Add("CompanyName"); queryBatch.SetClosures(qry, b => { var customers = new QBFCIterator<ICustomerRetList, ICustomerRet>(b); foreach (var customer in customers) { var qryMod = updateBatch.MsgSet.AppendCustomerModRq(); qryMod.ListID.SetValue(Safe.Value(customer.ListID)); qryMod.EditSequence.SetValue(Safe.Value(customer.EditSequence)); string tweakedName = Safe.Value(customer.CompanyName) + " tweaked by Zombie"; qryMod.CompanyName.SetValue(Safe.LimitedString(tweakedName, 41)); } }); StatusMgr.Trace("Running query for all edit sequences"); if (!queryBatch.Run()) return; StatusMgr.Trace("Updating all customers"); updateBatch.Run(); } }
private void button1_Click(object sender, RoutedEventArgs e) { using (var cn = ConnectionMgr.GetConnection()) { Console.WriteLine("Customer list from the current company file"); var batch = cn.NewBatch(); var qryCust = batch.MsgSet.AppendCustomerQueryRq(); batch.SetClosures(qryCust, b => { var customers = new QBFCIterator <ICustomerRetList, ICustomerRet>(b); foreach (var customer in customers) { // Console.WriteLine(Safe.Value(customer.FullName)); } }); batch.Run(); } }
/// <summary> /// Output a simple list of all customers in the company file /// </summary> public static void Show() { using (var cn = ConnectionMgr.GetConnection()) { Console.WriteLine("Customer list from the current company file"); var batch = cn.NewBatch(); var qryCust = batch.MsgSet.AppendCustomerQueryRq(); batch.SetClosures(qryCust, b => { var customers = new QBFCIterator<ICustomerRetList, ICustomerRet>(b); foreach (var customer in customers) { Console.WriteLine(Safe.Value(customer.FullName)); } }); batch.Run(); } }
/// <summary> /// Output a simple list of all customers in the company file /// </summary> public static void Show() { using (var cn = ConnectionMgr.GetConnection()) { Console.WriteLine("Customer list from the current company file"); var batch = cn.NewBatch(); var qryCust = batch.MsgSet.AppendCustomerQueryRq(); batch.SetClosures(qryCust, b => { var customers = new QBFCIterator <ICustomerRetList, ICustomerRet>(b); foreach (var customer in customers) { Console.WriteLine(Safe.Value(customer.FullName)); } }); batch.Run(); } }
public void QueryForItemsWithOneMissingSucceeds() { var sessionMock = new Mock<IQBSessionManager>(); var msgMock = new Mock<IMsgSetRequest>(); var queryMock = new Mock<ICustomerQuery>(); var requestListMock = new Mock<IRequestList>(); var requestMock = new Mock<IRequest>(); var responseSetMock = new Mock<IMsgSetResponse>(); var responseListMock = new Mock<IResponseList>(); var responseMock = new Mock<IResponse>(); var customerListMock = new Mock<ICustomerRetList>(); var customerMock = new Mock<ICustomerRet>(); var customerNameMock = new Mock<IQBStringType>(); sessionMock.Setup(x => x.CreateMsgSetRequest(It.IsAny<string>(), It.IsAny<short>(), It.IsAny<short>())).Returns(msgMock.Object); //for somre reason we have to explicitly setup these no-op methods on the mock //This only became necessary after the upgrade to QBSDK12 sessionMock.Setup(x => x.EndSession()); sessionMock.Setup(x => x.CloseConnection()); msgMock.Setup(x => x.AppendCustomerQueryRq()).Returns(queryMock.Object); msgMock.Setup(x => x.RequestList).Returns(requestListMock.Object); requestListMock.Setup(x => x.Count).Returns(1); requestListMock.Setup(x => x.GetAt(0)).Returns(requestMock.Object); requestMock.Setup(x => x.Detail).Returns(queryMock.Object); requestMock.Setup(x => x.RequestID).Returns(0); sessionMock.Setup(x => x.DoRequests(msgMock.Object)).Returns(responseSetMock.Object); responseSetMock.Setup(x => x.ResponseList).Returns(responseListMock.Object); responseListMock.Setup(x => x.Count).Returns(1); responseListMock.Setup(x => x.GetAt(0)).Returns(responseMock.Object); responseMock.Setup(x => x.RequestID).Returns("0"); responseMock.Setup(x => x.StatusCode).Returns(500); //500 means some object found, but others not responseMock.Setup(x => x.Detail).Returns(customerListMock.Object); customerListMock.Setup(x => x.Count).Returns(1); customerListMock.Setup(x => x.GetAt(0)).Returns(customerMock.Object); customerMock.Setup(x => x.Name).Returns(customerNameMock.Object); customerNameMock.Setup(x => x.GetValue()).Returns("Kilroy"); using (var cn = ConnectionMgr.GetTestConnection(sessionMock.Object)) { var batch = cn.NewBatch(); var query = batch.MsgSet.AppendCustomerQueryRq(); bool customerFound = false; batch.SetClosures(query, b => { var customers = new QBFCIterator<ICustomerRetList, ICustomerRet>(b); foreach(var customer in customers) { Console.WriteLine(Safe.Value(customer.Name)); customerFound = true; } }, null, true); Assert.Equal(true, batch.Run()); Assert.True(customerFound); } }
/// <summary> /// Wraps a custom field result /// </summary> /// <param name="dataExtensions">The field list to wrap</param> /// <param name="requireFieldMatch">if true, name mismatch will throw an exception</param> public CustomFieldGroup(IDataExtRetList dataExtensions, bool requireFieldMatch) { _fields = new QBFCIterator<IDataExtRetList, IDataExtRet>(dataExtensions); _requireFieldMatch = requireFieldMatch; }
public void QueryForItemsWithOneMissingSucceeds() { var sessionMock = new Mock <IQBSessionManager>(); var msgMock = new Mock <IMsgSetRequest>(); var queryMock = new Mock <ICustomerQuery>(); var requestListMock = new Mock <IRequestList>(); var requestMock = new Mock <IRequest>(); var responseSetMock = new Mock <IMsgSetResponse>(); var responseListMock = new Mock <IResponseList>(); var responseMock = new Mock <IResponse>(); var customerListMock = new Mock <ICustomerRetList>(); var customerMock = new Mock <ICustomerRet>(); var customerNameMock = new Mock <IQBStringType>(); sessionMock.Setup(x => x.CreateMsgSetRequest(It.IsAny <string>(), It.IsAny <short>(), It.IsAny <short>())).Returns(msgMock.Object); //for somre reason we have to explicitly setup these no-op methods on the mock //This only became necessary after the upgrade to QBSDK12 sessionMock.Setup(x => x.EndSession()); sessionMock.Setup(x => x.CloseConnection()); msgMock.Setup(x => x.AppendCustomerQueryRq()).Returns(queryMock.Object); msgMock.Setup(x => x.RequestList).Returns(requestListMock.Object); requestListMock.Setup(x => x.Count).Returns(1); requestListMock.Setup(x => x.GetAt(0)).Returns(requestMock.Object); requestMock.Setup(x => x.Detail).Returns(queryMock.Object); requestMock.Setup(x => x.RequestID).Returns(0); sessionMock.Setup(x => x.DoRequests(msgMock.Object)).Returns(responseSetMock.Object); responseSetMock.Setup(x => x.ResponseList).Returns(responseListMock.Object); responseListMock.Setup(x => x.Count).Returns(1); responseListMock.Setup(x => x.GetAt(0)).Returns(responseMock.Object); responseMock.Setup(x => x.RequestID).Returns("0"); responseMock.Setup(x => x.StatusCode).Returns(500); //500 means some object found, but others not responseMock.Setup(x => x.Detail).Returns(customerListMock.Object); customerListMock.Setup(x => x.Count).Returns(1); customerListMock.Setup(x => x.GetAt(0)).Returns(customerMock.Object); customerMock.Setup(x => x.Name).Returns(customerNameMock.Object); customerNameMock.Setup(x => x.GetValue()).Returns("Kilroy"); using (var cn = ConnectionMgr.GetTestConnection(sessionMock.Object)) { var batch = cn.NewBatch(); var query = batch.MsgSet.AppendCustomerQueryRq(); bool customerFound = false; batch.SetClosures(query, b => { var customers = new QBFCIterator <ICustomerRetList, ICustomerRet>(b); foreach (var customer in customers) { Console.WriteLine(Safe.Value(customer.Name)); customerFound = true; } }, null, true); Assert.Equal(true, batch.Run()); Assert.True(customerFound); } }