Beispiel #1
0
        public int AddCoin(CommonCoin theCoin)
        {
            try
            {
                if (backendCode.DoesCoinExistInDB(theCoin) == 0)
                {
                    if (theCoin.Mint != "W")
                    {
                        backendCode.AddTheCoin(theCoin);
                        return(1);
                    }
                    else if (theCoin.Type != "Quarter")
                    {
                        return(2);
                    }
                    else
                    {
                        backendCode.AddTheCoin(theCoin);
                        return(1);
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(0); // Did not add a coin to DB
        }
Beispiel #2
0
        public void DeleteTheCoin(CommonCoin theCoin)
        {
            SqlConnection connect = new SqlConnection(connectString);

            connect.Open();

            string sql = "DELETE tblCoinsDataSQL WHERE Type = '" + theCoin.Type + "' AND Mint = '" + theCoin.Mint + "' AND Year = '" + theCoin.Year + "' AND Name = '" + theCoin.Name + "'";

            if (connect.State == System.Data.ConnectionState.Open)
            {
                SqlCommand cmd = new SqlCommand(sql, connect);
                cmd.ExecuteNonQuery();
            }
        }
Beispiel #3
0
        public void AddTheCoin(CommonCoin theCoin)
        {
            SqlConnection connect = new SqlConnection(connectString);

            connect.Open();

            string sql = "INSERT INTO tblCoinsDataSQL (Year, Type, Mint, Name) VALUES('" + theCoin.Year + "','" + theCoin.Type + "','" + theCoin.Mint + "','" + theCoin.Name + "')";

            if (connect.State == System.Data.ConnectionState.Open)
            {
                SqlCommand cmd = new SqlCommand(sql, connect);
                cmd.ExecuteNonQuery();
            }
        }
Beispiel #4
0
        public int DeleteCoin(CommonCoin theCoin)
        {
            try
            {
                if (backendCode.DoesCoinExistInDB(theCoin) == 1)
                {
                    backendCode.DeleteTheCoin(theCoin);
                    return(0);
                }
            }
            catch (Exception ex)
            {
            }

            return(1); // Did not delete a coin to DB
        }
Beispiel #5
0
        public List <CommonCoin> GetData()
        {
            var listOfCoins = new List <CommonCoin>();

            SqlConnection connect = new SqlConnection(connectString);

            connect.Open();

            string sql = @"SELECT Year, Type, Mint, Name
                           FROM tblCoinsDataSQL
                           ORDER BY Type, Year, Name";

            if (connect.State == System.Data.ConnectionState.Open)
            {
                SqlCommand cmd = new SqlCommand(sql, connect);

                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var coin = new CommonCoin("", "", 0, "");

                        var type = reader["Type"] as string;
                        var mint = reader["Mint"] as string;
                        var year = (int)reader["Year"];
                        var name = reader["Name"] as string;

                        coin.Year = year;
                        coin.Type = type.Trim();
                        coin.Mint = mint.Trim();
                        coin.Name = name.Trim();
                        listOfCoins.Add(coin);
                    }

                    reader.Close();
                }
            }
            return(listOfCoins);
        }
Beispiel #6
0
        public int DoesCoinExistInDB(CommonCoin theCoin)
        {
            SqlConnection connect = new SqlConnection(connectString);

            connect.Open();
            string sql   = "SELECT count(*) FROM tblCoinsDataSQL WHERE Type = '" + theCoin.Type + "' AND Mint = '" + theCoin.Mint + "' AND Year = '" + theCoin.Year + "' AND Name = '" + theCoin.Name + "'";
            int    value = 0;

            if (connect.State == System.Data.ConnectionState.Open)
            {
                SqlCommand cmd = new SqlCommand(sql, connect);
                try
                {
                    value = (int)cmd.ExecuteScalar();
                }
                catch (Exception ex)
                {
                }
            }

            return((int)value);
        }
Beispiel #7
0
        public List <CommonCoin> SearchDatabase(CommonCoin theCoin)
        {
            var listOfCoins = new List <CommonCoin>();

            SqlConnection connect = new SqlConnection(connectString);

            connect.Open();

            string sql = "SELECT * FROM tblCoinsDataSQL WHERE Type = '" + theCoin.Type + "' AND Mint = '" + theCoin.Mint + "' AND Year = '" + theCoin.Year + "' AND Name = '" + theCoin.Name + "'";

            if (connect.State == System.Data.ConnectionState.Open)
            {
                SqlCommand cmd = new SqlCommand(sql, connect);

                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var coin = new CommonCoin("", "", 0, "");

                        var type = reader["Type"] as string;
                        var mint = reader["Mint"] as string;
                        var year = (int)reader["Year"];
                        var name = reader["Name"] as string;

                        coin.Year = year;
                        coin.Type = type.Trim();
                        coin.Mint = mint.Trim();
                        coin.Name = name.Trim();
                        listOfCoins.Add(coin);
                    }

                    reader.Close();
                }
            }
            return(listOfCoins);
        }
Beispiel #8
0
        public bool DoesCoinHaveSilver(CommonCoin theCoin)
        {
            switch (theCoin.Type.ToLower())
            {
            case "dime":
                return(theCoin.Year < 1965);

            case "quarter":
            case "dollar":
                bool contains = false;
                if ((theCoin.Year == 1975 || theCoin.Year == 1976) && theCoin.Mint.ToLower() == "s" && theCoin.Name.ToLower() == "bicentennial")
                {
                    contains = true;
                }
                else if (theCoin.Year < 1965)
                {
                    contains = true;
                }
                return(contains);

            case "half-dollar":
                bool halfContains = false;
                if ((theCoin.Year == 1975 || theCoin.Year == 1976) && theCoin.Mint.ToLower() == "s" && theCoin.Name.ToLower() == "bicentennial")
                {
                    halfContains = true;
                }
                else if (theCoin.Year < 1971)
                {
                    halfContains = true;
                }
                return(halfContains);

            default:
                return(false);
            }
        }
Beispiel #9
0
 public List <CommonCoin> SearchData(CommonCoin theCoin)
 {
     return(backendCode.SearchDatabase(theCoin));
 }
Beispiel #10
0
        public Tuple <bool, string> IsCoinKeyDate(CommonCoin theCoin)
        {
            string strMessage = "";
            bool   blnValue   = false;

            switch (theCoin.Type.ToLower())
            {
            case "penny":
                if ((theCoin.Year == 2009 && theCoin.Name.ToLower() == "lincoln") ||
                    ((theCoin.Year == 1943 || theCoin.Year == 1909) && theCoin.Name.ToLower() == "wheat"))
                {
                    strMessage = "You found a " + theCoin.Year + " penny. This is a keeper!";
                    blnValue   = true;
                }
                else if (theCoin.Year > 1908 && theCoin.Year < 1916 && theCoin.Mint.ToLower() == "s" && theCoin.Name.ToLower() == "wheat")
                {
                    strMessage = "Key date! Keeper!";
                }
                else if (theCoin.Year > 1909 && theCoin.Year < 1960 && theCoin.Name.ToLower() == "wheat")
                {
                    strMessage = "Keeper!";
                    blnValue   = true;
                }
                else if (theCoin.Name.ToLower() == "indian head" || theCoin.Name.ToLower() == "wheat" || theCoin.Name.ToLower() == "flying eagle")
                {
                    strMessage = "You found an " + theCoin.Name + " ! This is a keeper!";
                    blnValue   = true;
                }
                break;

            case "nickel":
                if (((theCoin.Year > 1929 && theCoin.Year < 1960) || theCoin.Year == 2009) && theCoin.Name.ToLower() == "Jefferson")
                {
                    strMessage = "You found a keeper!";
                    blnValue   = true;
                }
                else if (theCoin.Year == 2004 || theCoin.Year == 2005)
                {
                    strMessage = "You found a Louis and Clark commemerative coin!";
                    blnValue   = true;
                }
                else if (theCoin.Name.ToLower() == "buffalo" || theCoin.Name.ToLower() == "shield" || theCoin.Name.ToLower() == "war")
                {
                    strMessage = "You found a " + theCoin.Name + " !";
                    blnValue   = true;
                }
                break;

            case "dime":
                if (theCoin.Year == 2009)
                {
                    strMessage = "Keeper!";
                    blnValue   = true;
                }
                break;

            case "quarter":
                if (theCoin.Mint.ToLower() == "w" && theCoin.Year == 2019)
                {
                    strMessage = "2,000,000 coins were made of each!";
                    blnValue   = true;
                }
                else if (theCoin.Year == 2009 || theCoin.Year == 2010)
                {
                    strMessage = "Keeper!";
                }
                break;

            case "half-dollar":

                break;

            case "dollar":

                break;

            default:
                break;
            }

            var tuple = new Tuple <bool, string>(blnValue, strMessage);

            return(tuple);
        }