public List<FamilyDetail> QueryTransactionFamilies(string sessionToken, QueryTransactionsParameters queryTransactionsParameters, PagingParameters pagingParameters)
        {
            if (_msgFormat == MessageFormat.SOAP.ToString())
            {
                using (var client = new TMSOperationsClient(ConfigurationManager.AppSettings["Bindings.MgmtSoap"]))
                {
                    try
                    {
                        return client.QueryTransactionFamilies(sessionToken, queryTransactionsParameters, pagingParameters).ToList();
                    }
                    catch (FaultException ex)
                    {
                        SoapFaultHandler.HandleFaultException(ex);
                    }
                }
            }
            else // REST JSON or XML
            {
                var isJson = string.Equals(_msgFormat, MessageFormat.JSON.ToString());
                var requestString = RestBaseUri + "/transactionsFamily";
                var restQtf = new QueryTransactionsFamilies();

                // Convert the namespace from service reference to the generated proxies used by rest.
                restQtf.QueryTransactionsParameters = Utilities.SwapObjectsNamespace<schemas.ipcommerce.com.CWS.v2._0.DataServices.TMS.QueryTransactionsParameters>(queryTransactionsParameters);
                restQtf.PagingParameters = Utilities.SwapObjectsNamespace<schemas.ipcommerce.com.CWS.v2._0.DataServices.PagingParameters>(pagingParameters);

                var request = RestHelper.CreateRestRequest<QueryTransactionsFamilies>(restQtf, requestString, HttpMethod.POST, sessionToken, isJson);
                try
                {
                    var responseStr = RestHelper.GetResponse(request, isJson, false);
                    if (isJson)
                    {
                        var list = RestHelper.GetCWSObjectListFromJson<schemas.ipcommerce.com.CWS.v2._0.DataServices.TMS.FamilyDetail>(responseStr);
                        return list.Select(familyDetail => Utilities.SwapObjectsNamespace<TMS.FamilyDetail>(familyDetail)).ToList();
                    }
                    else
                    {
                        return RestHelper.GetCWSObjectListFromXml<TMS.FamilyDetail>(responseStr);
                    }
                }
                catch (Exception ex)
                {
                    RestFaultHandler.HandleFaultException(ex, isJson);
                }
            }
            return null;
        }
        private QueryTransactionsParameters QTP()
        {
            QueryTransactionsParameters QTP = new QueryTransactionsParameters();
            char[] splitter = { ',' };

            if (txtQTP_Amounts.Text.Length > 0)
            {
                List<decimal> Amt = new List<decimal>();
                string[] values = txtQTP_Amounts.Text.Split(splitter, StringSplitOptions.RemoveEmptyEntries);
                foreach (string s in values)
                {
                    try
                    {
                        decimal d = Convert.ToDecimal(s);
                        d = decimal.Parse(d.ToString("0.00"));//Amounts must be in format N.NN
                        Amt.Add(d);
                    }
                    catch { }
                }
                QTP.Amounts = Amt;
            }

            if (txtQTP_ApprovalCodes.Text.Length > 0)
                QTP.ApprovalCodes = new List<string>(txtQTP_ApprovalCodes.Text.Split(splitter, StringSplitOptions.RemoveEmptyEntries));
            if (txtQTP_BatchIds.Text.Length > 0)
                QTP.BatchIds = new List<string>(txtQTP_BatchIds.Text.Split(splitter, StringSplitOptions.RemoveEmptyEntries));
            if (txtQTP_OrderNumber.Text.Length > 0)
                QTP.OrderNumbers = new List<string>(txtQTP_OrderNumber.Text.Split(splitter, StringSplitOptions.RemoveEmptyEntries));

            //ToDo : add logic
            //QTP.CaptureDateRange = new DateRange();
            //QTP.CaptureDateRange.StartDateTime = dtpStartTimeTMS.Value.ToUniversalTime();
            //QTP.CaptureDateRange.EndDateTime = dtpEndTimeTMS.Value.ToUniversalTime();

            if (cboQTP_CaptureStates.Text.Length > 0)
            {
                List<CaptureState> TS = new List<CaptureState>();
                TS.Add((CaptureState)cboQTP_CaptureStates.SelectedItem);
                QTP.CaptureStates = TS;
            }

            if (cboQTP_CardTypes.Text.Length > 0)
            {
                List<TypeCardType> TS = new List<TypeCardType>();
                TS.Add((TypeCardType)cboQTP_CardTypes.SelectedItem);
                QTP.CardTypes = TS;
            }

            if (cboQTP_IsAcknowledged.Text.Length > 0)
            {
                if ((bool)cboQTP_IsAcknowledged.SelectedItem)
                    QTP.IsAcknowledged = BooleanParameter.True;
                else
                    QTP.IsAcknowledged = BooleanParameter.False;
            }

            if (txtQTP_MerchantProfileIds.Text.Length > 0)
                QTP.MerchantProfileIds = new List<string>(txtQTP_MerchantProfileIds.Text.Split(splitter, StringSplitOptions.RemoveEmptyEntries));

            if (cboQTP_QueryType.Text.Length > 0)
                QTP.QueryType = (QueryType)cboQTP_QueryType.SelectedItem;

            if (txtQTP_ServiceIds.Text.Length > 0)
                QTP.ServiceIds = new List<string>(txtQTP_ServiceIds.Text.Split(splitter, StringSplitOptions.RemoveEmptyEntries));

            if (txtQTP_ServiceKeys.Text.Length > 0)
                QTP.ServiceKeys = new List<string>(txtQTP_ServiceKeys.Text.Split(splitter, StringSplitOptions.RemoveEmptyEntries));

            //ToDo : add logic
            if (txtQTP_TransactionClassTypePairs.Text.Length > 0)
            {
                List<TransactionClassTypePair> TCTP = new List<TransactionClassTypePair>();
                TCTP.Add(new TransactionClassTypePair());
                QTP.TransactionClassTypePairs = TCTP;
            }

            ////Specify batch paramaters
            QTP.TransactionDateRange = new DateRange();
            QTP.TransactionDateRange.StartDateTime = dtpStartTimeTMS.Value.ToUniversalTime();
            QTP.TransactionDateRange.EndDateTime = dtpEndTimeTMS.Value.ToUniversalTime();
          

            if (txtQTP_TransactionIds.Text.Length > 0)
                QTP.TransactionIds = new List<string>(txtQTP_TransactionIds.Text.Replace(" ", "").Split(splitter, StringSplitOptions.RemoveEmptyEntries));

            if (cboQTP_TransactionStates.Text.Length > 0)
            {
                List<TransactionState> TS = new List<TransactionState>();
                TS.Add((TransactionState)cboQTP_TransactionStates.SelectedItem);
                QTP.TransactionStates = TS;
            }

            return QTP;
        }
        private QueryTransactionsParameters QTP()
        {
            QueryTransactionsParameters QTP = new QueryTransactionsParameters();
            char[] splitter = { ',' };

            if (txtQTP_Amounts.Text.Length > 0)
            {
                List<decimal> Amt = new List<decimal>();
                string[] values = txtQTP_Amounts.Text.Split(splitter, StringSplitOptions.RemoveEmptyEntries);
                foreach (string s in values)
                {
                    try
                    {
                        decimal d = Convert.ToDecimal(s);
                        d = decimal.Parse(d.ToString("0.00"));//Amounts must be in format N.NN
                        Amt.Add(d);
                    }
                    catch { }
                }
                QTP.Amounts = Amt;
            }

            if (txtQTP_ApprovalCodes.Text.Length > 0)
                QTP.ApprovalCodes = new List<string>(txtQTP_ApprovalCodes.Text.Split(splitter, StringSplitOptions.RemoveEmptyEntries));
            if (txtQTP_BatchIds.Text.Length > 0)
                QTP.BatchIds = new List<string>(txtQTP_BatchIds.Text.Split(splitter, StringSplitOptions.RemoveEmptyEntries));
            if (txtQTP_OrderNumber.Text.Length > 0)
                QTP.OrderNumbers = new List<string>(txtQTP_OrderNumber.Text.Split(splitter, StringSplitOptions.RemoveEmptyEntries));

            //ToDo : add logic
            //QTP.CaptureDateRange = new DateRange();
            //QTP.CaptureDateRange.StartDateTime = dtpStartTimeTMS.Value.ToUniversalTime();
            //QTP.CaptureDateRange.EndDateTime = dtpEndTimeTMS.Value.ToUniversalTime();

            if (cboQTP_CaptureStates.Text.Length > 0)
            {
                List<CaptureState> TS = new List<CaptureState>();
                TS.Add((CaptureState)cboQTP_CaptureStates.SelectedItem);
                QTP.CaptureStates = TS;
            }

            if (cboQTP_CardTypes.Text.Length > 0)
            {
                List<TypeCardType> TS = new List<TypeCardType>();
                TS.Add((TypeCardType)cboQTP_CardTypes.SelectedItem);
                QTP.CardTypes = TS;
            }

            if (cboQTP_IsAcknowledged.Text.Length > 0)
            {
                if ((bool)cboQTP_IsAcknowledged.SelectedItem)
                    QTP.IsAcknowledged = BooleanParameter.True;
                else
                    QTP.IsAcknowledged = BooleanParameter.False;
            }

            if (CboQTP_MerchantProfileIds.Text.Length > 0)
                QTP.MerchantProfileIds = new List<string>(CboQTP_MerchantProfileIds.Text.Split(splitter, StringSplitOptions.RemoveEmptyEntries));

            if (cboQTP_QueryType.Text.Length > 0)
                QTP.QueryType = (QueryType)cboQTP_QueryType.SelectedItem;

            if (CboQTP_ServiceIds.Text.Length > 0)
                QTP.ServiceIds = new List<string>(CboQTP_ServiceIds.Text.Split(splitter, StringSplitOptions.RemoveEmptyEntries));

            if (txtQTP_ServiceKeys.Text.Length > 0)
                QTP.ServiceKeys = new List<string>(txtQTP_ServiceKeys.Text.Split(splitter, StringSplitOptions.RemoveEmptyEntries));

            //ToDo : add logic
            if (txtQTP_TransactionClassTypePairs.Text.Length > 0)
            {
                List<TransactionClassTypePair> TCTP = new List<TransactionClassTypePair>();
                TCTP.Add(new TransactionClassTypePair());
                QTP.TransactionClassTypePairs = TCTP;
            }

            ////Specify batch paramaters
            QTP.TransactionDateRange = new DateRange();
            QTP.TransactionDateRange.StartDateTime = dtpStartTimeTMS.Value.ToUniversalTime();
            QTP.TransactionDateRange.EndDateTime = dtpEndTimeTMS.Value.ToUniversalTime();

            List<string> txnIds = new List<string>();
            if (txtQTP_TransactionIds.Text.Length > 0)
            {
                //First Process any transactionId's in the text box
                txnIds = new List<string>(txtQTP_TransactionIds.Text.Replace(" ", "").Split(splitter, StringSplitOptions.RemoveEmptyEntries));
            }
            //Now check to see if any are listed in the Check List.
            if(chkUseTransactionIdSelected.Checked && chklstTMSResults.CheckedItems.Count > 0)
            {
                //Iterate through the checked list box and add transactionId(s)
                foreach (object itemChecked in chklstTMSResults.CheckedItems)
                {
                    if (itemChecked.GetType().ToString() == "SampleCode.SummaryDetailVal")
                    {
                        txtQTP_TransactionIds.Text = txtQTP_TransactionIds.Text + ((SummaryDetailVal)(itemChecked)).SD.TransactionInformation.TransactionId + ", ";
                        txnIds.Add(((SummaryDetailVal)(itemChecked)).SD.TransactionInformation.TransactionId);
                    }

                    if (itemChecked.GetType().ToString() == "SampleCode.TransactionDetailVal")
                    {
                        txtQTP_TransactionIds.Text = txtQTP_TransactionIds.Text + ((TransactionDetailVal)(itemChecked)).TD.TransactionInformation.TransactionId + ", ";
                        txnIds.Add(((TransactionDetailVal)(itemChecked)).TD.TransactionInformation.TransactionId);
                    }

                    //if (itemChecked.GetType().ToString() == "SampleCode.FamilyDetailVal")
                    //    txnIds.Add(((FamilyDetailVal)(itemChecked)).FD.TransactionIds);

                    //if (itemChecked.GetType().ToString() == "SampleCode.BatchDetailDataVal")
                    //    txnIds.Add(((BatchDetailDataVal)(itemChecked)).BDD.TransactionIds);
                }
            }
            //Note : Only set transactionId's if one or more actually exist. Otherwise the result set will be empty
            if (txnIds.Count > 0)
                QTP.TransactionIds = txnIds;

            if (cboQTP_TransactionStates.Text.Length > 0)
            {
                List<TransactionState> TS = new List<TransactionState>();
                TS.Add((TransactionState)cboQTP_TransactionStates.SelectedItem);
                QTP.TransactionStates = TS;
            }

            return QTP;
        }
        private QueryTransactionsParameters QTP()
        {
            QueryTransactionsParameters QTP = new QueryTransactionsParameters();

            char[] splitter = { ',' };

            if (txtQTP_Amounts.Text.Length > 0)
            {
                List <decimal> Amt    = new List <decimal>();
                string[]       values = txtQTP_Amounts.Text.Split(splitter, StringSplitOptions.RemoveEmptyEntries);
                foreach (string s in values)
                {
                    try
                    {
                        decimal d = Convert.ToDecimal(s);
                        d = decimal.Parse(d.ToString("0.00"));//Amounts must be in format N.NN
                        Amt.Add(d);
                    }
                    catch { }
                }
                QTP.Amounts = Amt;
            }

            if (txtQTP_ApprovalCodes.Text.Length > 0)
            {
                QTP.ApprovalCodes = new List <string>(txtQTP_ApprovalCodes.Text.Split(splitter, StringSplitOptions.RemoveEmptyEntries));
            }
            if (txtQTP_BatchIds.Text.Length > 0)
            {
                QTP.BatchIds = new List <string>(txtQTP_BatchIds.Text.Split(splitter, StringSplitOptions.RemoveEmptyEntries));
            }
            if (txtQTP_OrderNumber.Text.Length > 0)
            {
                QTP.OrderNumbers = new List <string>(txtQTP_OrderNumber.Text.Split(splitter, StringSplitOptions.RemoveEmptyEntries));
            }

            //ToDo : add logic
            //QTP.CaptureDateRange = new DateRange();
            //QTP.CaptureDateRange.StartDateTime = dtpStartTimeTMS.Value.ToUniversalTime();
            //QTP.CaptureDateRange.EndDateTime = dtpEndTimeTMS.Value.ToUniversalTime();

            if (cboQTP_CaptureStates.Text.Length > 0)
            {
                List <CaptureState> TS = new List <CaptureState>();
                TS.Add((CaptureState)cboQTP_CaptureStates.SelectedItem);
                QTP.CaptureStates = TS;
            }

            if (cboQTP_CardTypes.Text.Length > 0)
            {
                List <TypeCardType> TS = new List <TypeCardType>();
                TS.Add((TypeCardType)cboQTP_CardTypes.SelectedItem);
                QTP.CardTypes = TS;
            }

            if (cboQTP_IsAcknowledged.Text.Length > 0)
            {
                if ((bool)cboQTP_IsAcknowledged.SelectedItem)
                {
                    QTP.IsAcknowledged = BooleanParameter.True;
                }
                else
                {
                    QTP.IsAcknowledged = BooleanParameter.False;
                }
            }

            if (txtQTP_MerchantProfileIds.Text.Length > 0)
            {
                QTP.MerchantProfileIds = new List <string>(txtQTP_MerchantProfileIds.Text.Split(splitter, StringSplitOptions.RemoveEmptyEntries));
            }

            if (cboQTP_QueryType.Text.Length > 0)
            {
                QTP.QueryType = (QueryType)cboQTP_QueryType.SelectedItem;
            }

            if (txtQTP_ServiceIds.Text.Length > 0)
            {
                QTP.ServiceIds = new List <string>(txtQTP_ServiceIds.Text.Split(splitter, StringSplitOptions.RemoveEmptyEntries));
            }

            if (txtQTP_ServiceKeys.Text.Length > 0)
            {
                QTP.ServiceKeys = new List <string>(txtQTP_ServiceKeys.Text.Split(splitter, StringSplitOptions.RemoveEmptyEntries));
            }

            //ToDo : add logic
            if (txtQTP_TransactionClassTypePairs.Text.Length > 0)
            {
                List <TransactionClassTypePair> TCTP = new List <TransactionClassTypePair>();
                TCTP.Add(new TransactionClassTypePair());
                QTP.TransactionClassTypePairs = TCTP;
            }

            ////Specify batch paramaters
            QTP.TransactionDateRange = new DateRange();
            QTP.TransactionDateRange.StartDateTime = dtpStartTimeTMS.Value.ToUniversalTime();
            QTP.TransactionDateRange.EndDateTime   = dtpEndTimeTMS.Value.ToUniversalTime();


            if (txtQTP_TransactionIds.Text.Length > 0)
            {
                QTP.TransactionIds = new List <string>(txtQTP_TransactionIds.Text.Replace(" ", "").Split(splitter, StringSplitOptions.RemoveEmptyEntries));
            }

            if (cboQTP_TransactionStates.Text.Length > 0)
            {
                List <TransactionState> TS = new List <TransactionState>();
                TS.Add((TransactionState)cboQTP_TransactionStates.SelectedItem);
                QTP.TransactionStates = TS;
            }

            return(QTP);
        }
        public static QueryTransactionsParameters CreateQueryTransactionParameters(QueryType queryType = QueryType.OR, List<string> transactionIds = null)
        {
            var qtp = new QueryTransactionsParameters();

            if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["QueryType"]))
                qtp.QueryType = (QueryType)Enum.Parse(typeof(QueryType), ConfigurationManager.AppSettings["QueryType"]); // Required
            else
                qtp.QueryType = queryType;

            if (transactionIds != null)
                qtp.TransactionIds = transactionIds.ToArray();

            if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["CaptureStartDate"]) && !string.IsNullOrEmpty(ConfigurationManager.AppSettings["CaptureEndDate"]))
            {
                qtp.CaptureDateRange = new DateRange();
                qtp.CaptureDateRange.StartDateTime = DateTime.Parse(ConfigurationManager.AppSettings["CaptureStartDate"]);
                qtp.CaptureDateRange.EndDateTime = DateTime.Parse(ConfigurationManager.AppSettings["CaptureEndDate"]);
            }

            if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["TransactionStartDate"]) && !string.IsNullOrEmpty(ConfigurationManager.AppSettings["TransactionEndDate"]))
            {
                qtp.TransactionDateRange = new DateRange();
                qtp.TransactionDateRange.StartDateTime = DateTime.Parse(ConfigurationManager.AppSettings["TransactionStartDate"]);
                qtp.TransactionDateRange.EndDateTime = DateTime.Parse(ConfigurationManager.AppSettings["TransactionEndDate"]);
            }
            else
            {
                qtp.TransactionDateRange = new DateRange();
                qtp.TransactionDateRange.StartDateTime = DateTime.Now.AddDays(-5);
                qtp.TransactionDateRange.EndDateTime = DateTime.Now;
            }

            if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["IsAcknowledged"]))
                qtp.IsAcknowledged = (BooleanParameter)Enum.Parse(typeof(BooleanParameter), ConfigurationManager.AppSettings["IsAcknowledged"]);

            // Other optional fields.
            //qtp.Amounts // List<Decimal> - Collection of specific transaction amount values from transaciton requests matching the amount authorized, returned, adjusted, or captured.
            //qtp.ApprovalCodes // List<String> - Collection of specific ApprovalCode values from transaction responses.
            //qtp.BatchIds // List<String> - Collection of specific BatchId values from transaction responses.
            //qtp.CaptureStates // List<CaptureState> - Collection of capture states.
            //qtp.CardTypes // List<TypeCardType> - Collection of TypeCardTypes
            //qtp.CustomerIds // List<String> - Collection of specific customerId values from transaction requests.
            //qtp.IsAcknowledged // Boolean - Indicates wheather the transaction was acknowledged.
            //qtp.MerchantProfileIds // List<String> - Collection of specific Merchant Profile values from transaction requests.
            //qtp.OrderNumbers // List<String> - Collection of specific OrderNumber values from transaction requests.
            //qtp.ServiceIds // List<String> - Collection of ServiceIds
            //qtp.ServiceKeys // List<String> - Collection of ServiceKeys
            //qtp.TransactionClassTypePairs // List<String> - Collection of specific transaction class/transaction type paris.
            //qtp.TransactionStates // List<TransactionState> - Collection of specific trasaction states
            return qtp;
        }