-3

I have 3 projects in the same solution, 3-tier architecture.

However I am failing to show my presentations in the presentation layer I get the error CS0103, my thought is that the layer cannot access the methods used in the layer it references. If that's the case then how can I reference these methods or suggest an easy way to do this?

User Image

My presentation layer references the following code

using Data_Link;
using static Data_Link.Program;
using Microsoft.VisualBasic.FileIO;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Business_Logic
{
    public class Program 
    {


        List<Card> CrackableCards = GetCrackablePINS(AllCards);
        List<Card> ExpiredCards = GetExpiredCards(AllCards);
        List<Card> ExpiringCards = GetExpiringCards(AllCards);
        List<Card> HNWIs = GetHNWI(AllCards);

        public static List<Card> AllCards { get; private set; }

        /* List<Card> AllCards = new List<Card>();
         public int[] computeFrequency(List<LotteryEntry> historicalData)
         public static 

         */
        //Returns crackable pins
        private static List<Card> GetCrackablePINS(List<Card> cards)
        {
            List<Card> CrackableCards = GetCrackablePINS(AllCards);
            List<Card> results = new List<Card>();
            foreach (var card in cards)
            {
                if (IsCrackable(card.CardPIN))
                    results.Add(card);
            }
            return results;

        }
        //Returns expired cards
        private static List<Card> GetExpiredCards(List<Card> cards)
        {
            List<Card> results = new List<Card>();
            foreach (var card in cards)
            {
                if (HasExpired(card.ExpiryDate))
                    results.Add(card);
            }
            return results;
        }
        //Returns expiring cards
        private static List<Card> GetExpiringCards(List<Card> cards)
        {
            List<Card> results = new List<Card>();
            foreach (var card in cards)
            {
                if (IsExpiring(card.ExpiryDate))
                    results.Add(card);
            }
            return results;
        }
        //Returns HNWIs
        private static List<Card> GetHNWI(List<Card> cards)
        {
            List<Card> results = new List<Card>();
            foreach (var card in cards)
            {
                if (IsHNWI(card.CardLimit))
                    results.Add(card);
            }
            return results;
        }
        //Generates report in csv
         private void GenerateReport(List<Card> cardCriteria, string fileName)
        {
            string heading = "Card Type Code,Card Type Full Name,Issuing Bank,Card Number,Card Holder's Name,CVV/CVV2,Issue Date,Expiry Date,Billing Date,Card PIN,Credit Limit";
            File.WriteAllText(fileName, heading);
            foreach (var card in cardCriteria)
            {
                try
                {
                    string details = card.CardTypeCode + "," + card.CardTypeFullName + "," + card.IssusingBank + "," + card.CardNumber + "," + card.CardHolderName + "," + card.CVV + "," + card.IssueDate + "," + card.ExpiryDate + "," + card.BillingDate + "," + card.CardPIN + "," + card.CardLimit;
                    File.AppendAllText(fileName, details);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
        //Checks if a card pin is crackable
        private static bool IsCrackable(string PIN)
        {
            if (PIN[0] == PIN[1] || PIN[1] == PIN[2] || PIN[2] == PIN[3])
            {
                return true;
            }
            else if ((int)PIN[0] == (int)PIN[1] - 1 && (int)PIN[1] == (int)PIN[2] - 1 && (int)PIN[2] == PIN[3] - 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        //Checks if the card has expired
        private static bool HasExpired(string date)
        {
            string[] dateString = date.Split('/');
            int month = int.Parse(dateString[0]);
            int year = int.Parse(dateString[1]);
            if (month <= 2 && year <= 2020)
                return true;
            else
                return false;
        }
        //Checks if the card is expiring
        private static bool IsExpiring(string date)
        {
            string[] dateString = date.Split('/');
            int month = int.Parse(dateString[0]);
            int year = int.Parse(dateString[1]);
            if (month == DateTime.Now.Month && year == DateTime.Now.Year)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        //Checks if a card is an HNWI
        private static bool IsHNWI(int HNWI)
        {
            const int limit = 149999;
            if (HNWI > limit)
                return true;
            else
                return false;
        }
    }
}
Enigmativity
  • 113,464
  • 11
  • 89
  • 172
  • 1
    All `private` Fields and Methods. – Jimi Mar 21 '20 at 10:56
  • 1
    Pro tip: questions that have a title that is just general pleading will generally get closed here. Titles should always be indicative of a post's content. – halfer Mar 21 '20 at 11:03
  • @Jimi I tried changing the methods into public but still – Lebea Tshwarelo Tevin Kdot Mar 21 '20 at 11:03
  • You are using static methods, but the fields are per instance. Either declare your fields as `static` or instantiate a new instance of Program like this in the Main : `var myProgramInstance = new Program();`, and use `myProgramInstance.CrackableCards` for lists , etc.. – Pac0 Mar 21 '20 at 11:04
  • as the Main method is static, it doesn't corresponds to an instance, so it doesn't "see" the lists you declared . But you can create an instance without issue. You need to get basic training on OOP (Object Oreinted Programmin) for the understanding. – Pac0 Mar 21 '20 at 11:07
  • @Pac0 I dont understand which fields and how – Lebea Tshwarelo Tevin Kdot Mar 21 '20 at 11:08
  • Ah, I haven't noticed it's not the same namespace. See Jasper Kent answer. – Pac0 Mar 21 '20 at 11:08

1 Answers1

1

You're using static BusinessLogic.Program will allow public static member of BusinessLogic.Program to be accessed.

However, your fields (ExpiredCards etc) are non-static and private (by default). Precede each of this with public static.

That said, it would probably be more maintainable to avoid static data. Instead, create and instance of BusinessLogic.Program inside Main().

Jasper Kent
  • 3,546
  • 15
  • 21