public ClientInformationAndAgeingBalances GetMatchedClientInfo(int clientId)
        {
            ClientInformationAndAgeingBalances information = null;

            //ArrayList arrClist = new ArrayList();
            //arrClist.Add(clientId);

            //DataSet theDs = clients.CACrLimitFromDrMgt(arrClist);
            //if (theDs != null)
            //{
            //     //theDs.Tables.
            //}


            using (SqlConnection connection = CreateConnection())
            {
                //djhjhdfjhdfh
                using (SqlDataReader dataReader = SqlHelper.ExecuteReader(connection,
                                                                          CommandType.StoredProcedure,
                                                                          "stGetClientAgingAndCurrent",
                                                                          CreateClientIdAndUserParameters(clientId, 7)))
                {
                    CleverReader reader = new CleverReader(dataReader);
                    if (reader.Read())
                    {
                        ClientInformation clientInformation = new ClientInformationBuilder(reader).Build();
                        reader.NextResult();
                        TransactionSummary transactionSummary = new TransactionSummaryBuilder(reader).Build();
                        reader.NextResult();
                        AgeingBalances ageingBalances = new AgeingBalancesBuilder(reader).Build();

                        information = new ClientInformationAndAgeingBalances(ageingBalances, clientInformation,
                                                                             transactionSummary);
                    }
                }
            }

            return(information);
        }
        public ClientAndCustomerInformation GetMatchedCustomerInfo(int customerId, int clientId)
        {
            if (customerId == int.MinValue || customerId == 0)
            {
                return(null);
            }

            ClientAndCustomerInformation clientAndCustomerInformation = null;

            using (SqlConnection connection = CreateConnection())
            {
                //DataTable schema = null;
                //using (var schemaCommand = new SqlCommand("exec GetCustomerInfo 910823", connection))
                //{
                //    connection.Open();
                //    using (var reader = schemaCommand.ExecuteReader(CommandBehavior.SchemaOnly))
                //    {
                //        reader.NextResult();
                //        reader.Read();
                //        schema = reader.GetSchemaTable();
                //        reader.NextResult();
                //        reader.Read();
                //        schema = reader.GetSchemaTable();
                //        reader.NextResult();
                //        reader.Read();
                //        schema = reader.GetSchemaTable();
                //    }
                //}
                //DataTable schema = null;

                using (SqlDataReader dataReader = SqlHelper.ExecuteReader(connection,
                                                                          CommandType.StoredProcedure,
                                                                          "GetCustomerInfo",
                                                                          CreateCustomerIdParameter(customerId, false)))

                {
                    CleverReader reader = new CleverReader(dataReader);
                    if (!reader.IsNull && reader.Read())
                    {
                        IDate   lastPaid   = reader.ToNullableDate("lastRecDt");
                        decimal lastAmount = reader.ToDecimal("lastRecAmt");

                        reader.NextResult();

                        AgeingBalances ageingBalances = new AgeingBalancesBuilder(reader).Build();

                        reader.NextResult();
                        reader.Read();

                        CffClient client = new CffClientBuilder(reader).Build();

                        //CffClient client = new CffClientBuilderCleverReader(reader).Build();
                        CffClientInformation cffClientInformation = new CffClientInformationBuilder(reader).Build(client);
                        ClientCustomerTerm   clientCustomerTerm   = new ClientCustomerTermBuilder(reader).Build();

                        CffCustomer            customer            = new CffCustomerBuilder(reader).Build(customerId);
                        CffCustomerInformation customerInformation =
                            new CffCustomerInformationBuilder(reader).Build(customer, lastPaid, lastAmount,
                                                                            clientCustomerTerm, ageingBalances);

                        //MSarza [20151001]
                        reader.NextResult();
                        reader.Read();
                        CffCustomerContact defaultCustContact = new CffCustomerContactBuilder(reader).Build();

                        //MSarza [20150731]
                        reader.NextResult();
                        reader.Read();
                        CffMgtDetails cffMgtDetails = new CffMgtDetailsBuilder(reader).Build();

                        clientAndCustomerInformation = new ClientAndCustomerInformation(customerInformation,
                                                                                        cffClientInformation,
                                                                                        defaultCustContact,         //MSarza [20150731]
                                                                                        cffMgtDetails);             //MSarza [20150731]
                    }
                }
            }
            return(clientAndCustomerInformation);
        }