Esempio n. 1
0
 /// <summary>
 /// Check if the input number is existence in the database
 /// </summary>
 /// <param name="number"></param>
 public NumberModel CheckDuplicate(NumberModel number)
 {
     try
     {
         using (SqlConnection con = new SqlConnection(_connectionString))
         {
             con.Open();
             cmd = new SqlCommand($"Select * from NumberList where number='{number.PhoneNumber}'", con);
             cmd.ExecuteNonQuery();
             rdr = cmd.ExecuteReader();
             //find the phonenumber, if exist
             while (rdr.Read())
             {
                 NumberModel foundnumber = new NumberModel
                 {
                     Id              = Convert.ToInt32(rdr[0]),
                     PhoneNumber     = Convert.ToInt32(rdr[1]),
                     NetworkProvider = Convert.ToString(rdr[2])
                 };
                 return(foundnumber);
             }
             return(null);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Check Feng Shui of single input number
        /// </summary>
        /// <param name="number"></param>
        public static bool CheckSingleNumber(NumberModel number)
        {
            int firstSum  = 0;
            int secondSum = 0;
            int phone     = number.PhoneNumber;         //create a temp phonenumber variable for calculation

            if (tabooList.Contains(phone % 100))
            {
                return(false);                                            //if last 2 digit in tabooList, not good FengShui
            }
            else
            {
                for (int i = 0; i < 10; i++)
                {
                    if (i < 5)                    //the last 5 digit sum will be 2nd-sum
                    {
                        secondSum += phone % 10;
                        phone      = phone / 10;
                    }
                    else                    //the first 4 digit(the first digit is 0) will be 1st-sum
                    {
                        firstSum += phone % 10;
                        phone     = phone / 10;
                    }
                }
                Convert.ToString(firstSum);                 //Convert sum to String to get the right proportion for 24/28 (no mislead to 12/14)
                Convert.ToString(secondSum);
                if (sumProportion.Contains($"{firstSum}/{secondSum}") && nicePairList.Contains(number.PhoneNumber % 100))
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 3
0
        /// <summary>
        /// Check if the input number has existed in database,
        /// if existed return the number,
        /// if not return null
        /// </summary>
        /// <param name="number"></param>
        /// <returns></returns>
        public static NumberModel CheckDuplicate(NumberModel number)
        {
            //GetAppSettingsFile();
            var numberDal = new NumberDAL();

            if (numberDal.CheckDuplicate(number) == null)
            {
                return(null);
            }
            return(number);
        }
Esempio n. 4
0
 /// <summary>
 /// Add the given number to database(has been checked existence)
 /// </summary>
 /// <param name="number"></param>
 public void AddNumber(NumberModel number)
 {
     try
     {
         using (SqlConnection con = new SqlConnection(_connectionString))
         {
             con.Open();
             cmd = new SqlCommand($"INSERT INTO NumberList VALUES((SELECT max(Id)+1 FROM NumberList),{number.PhoneNumber},'{number.NetworkProvider}')", con);
             cmd.ExecuteNonQuery();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Add the input number to database if not existed
        /// </summary>
        /// <param name="numberModel"></param>
        public static void AddNumberToDb(NumberModel number)
        {
            var numberDal = new NumberDAL();

            numberDal.AddNumber(number);
        }
Esempio n. 6
0
        /// <summary>
        /// Respond based on the user's choice
        /// </summary>
        /// <param name="choice"></param>
        public static void Choose(int choice)
        {
            switch (choice)
            {
            case 1:
                Console.WriteLine("\n\t|---------------------------------------|");
                Console.WriteLine("\t|All the known good Feng Shui numbers\t|");
                Console.WriteLine("\t|Phone Number \t|\tProvider\t|");
                NumberController.GetList(null);
                break;

            case 2:
                Console.WriteLine("\n\t|---------------------------------------|");
                Console.WriteLine("\t|The good Feng Shui Viettel numbers\t|");
                Console.WriteLine("\t|Phone Number \t|\tProvider\t|");
                NumberController.GetList("Viettel");
                break;

            case 3:
                Console.WriteLine("\n\t|---------------------------------------|");
                Console.WriteLine("\t|The known good Feng Shui Mobi numbers\t|");
                Console.WriteLine("\t|Phone Number \t|\tProvider\t|");
                NumberController.GetList("Mobi");
                break;

            case 4:
                Console.WriteLine("\n\t|---------------------------------------|");
                Console.WriteLine("\t|The known good Feng Shui Vina numbers\t|");
                Console.WriteLine("\t|Phone Number \t|\tProvider\t|");
                NumberController.GetList("Vina");
                break;

            case 5:
                NumberModel number = AddPhone();                         //create a NumberModel object to contain data
                if (number.PhoneNumber == 999)
                {
                    break;                                                            //Check again to make sure when the number is 999 will break and back to main menu
                }
                NumberModel checkDuplicate = NumberController.CheckDuplicate(number); //check if the number has existed in database
                if (checkDuplicate == null)                                           //if not existed, add to db and check FengShui
                {
                    NumberController.AddNumberToDb(number);
                    Console.WriteLine($"0{number.PhoneNumber} has been added to the database");
                    bool check = NumberController.CheckSingleNumber(number);
                    if (check)
                    {
                        Console.WriteLine($"0{number.PhoneNumber} is a Good Feng Shui Number");
                    }
                    else
                    {
                        Console.WriteLine($"0{number.PhoneNumber} is a Not Good Feng Shui Number");
                    }
                    break;
                }
                else                         //if existed, print the alert and FengShui status
                {
                    bool check = NumberController.CheckSingleNumber(number);
                    Console.WriteLine($"0{number.PhoneNumber} has been existed in the database");
                    Console.Write($"and ");
                    if (check)
                    {
                        Console.WriteLine($"0{number.PhoneNumber} is a Good Feng Shui Number");
                    }
                    else
                    {
                        Console.WriteLine($"0{number.PhoneNumber} is a Not Good Feng Shui Number");
                    }
                    break;
                }

            case 6:
                Console.WriteLine("----------------------------------------------------------------------------------------------------------------------");
                Console.WriteLine("(1). The last 2 num chars is taboo: ");
                Console.WriteLine("If this rule is violated, other criterias at (2) are not checked in any case.");
                Console.WriteLine("00, 66, 04, 45, 85, 27, 67, ");
                Console.WriteLine("17, 57, 97, 98, 58, 42, 82 69");
                Console.WriteLine("(2) Good feng shui numbers: match all criteria below:");
                Console.WriteLine("Total first 5 nums / Total last 5 nums: matches 1 in 2 conditions: 24 / 29 or 24 / 28");
                Console.WriteLine("Last nice pair of numbers: 19, 24, 26, 37, 34 ");
                break;

            default:
                break;
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Menu to add a new phonenumber and check Validation, if valid return the phonenumber to continue check FengShui
        /// </summary>
        /// <returns></returns>
        public static NumberModel AddPhone()
        {
            int    phoneNumber = 0;
            int    choiceProvider;
            string networkProvider = "";

            do
            {
                Console.WriteLine("\n\t|---------------------------------------------\t|");
                Console.WriteLine("\t|Please choose the providers (Enter number):\t|");
                Console.WriteLine("\t|1/Viettel: 086xxx, 096xxx, 097xxx\t\t|");
                Console.WriteLine("\t|2/Mobi: 089xxx, 090xxx, 093xxx\t\t\t|");
                Console.WriteLine("\t|3/Vina: 088xxx, 091xxx, 094xxx\t\t\t|");
                Console.WriteLine("\t|----------------------------------------------\t|");
                Console.Write("\t\tPlease choose: ");
                int.TryParse(Console.ReadLine(), out choiceProvider);
            }while (choiceProvider != 1 && choiceProvider != 2 && choiceProvider != 3);
            switch (choiceProvider)
            {
            case 1:
                networkProvider = "Viettel";
                do
                {
                    Console.WriteLine("\nPlease input the phone number (Enter 999 to comeback)");
                    Console.WriteLine("Viettel phone number has to start with 086,096,097 and has 10 digit");
                    Console.Write("Input number: ");
                    int.TryParse(Console.ReadLine(), out phoneNumber);
                    if (phoneNumber == 999)
                    {
                        break;
                    }
                } while (phoneNumber / 10000000 != 86 && phoneNumber / 10000000 != 96 && phoneNumber / 10000000 != 97 && phoneNumber.ToString().Length != 9);

                break;

            case 2:
                networkProvider = "Mobi";
                do
                {
                    Console.WriteLine("\nPlease input the phone number (Enter 999 to comeback)");
                    Console.WriteLine("Mobi phone number has to start with 089, 090, 093 and has 10 digit");
                    Console.Write("Input number: ");
                    int.TryParse(Console.ReadLine(), out phoneNumber);
                    if (phoneNumber == 999)
                    {
                        break;
                    }
                } while (phoneNumber / 10000000 != 89 && phoneNumber / 10000000 != 90 && phoneNumber / 10000000 != 93 && phoneNumber.ToString().Length != 9);

                break;

            case 3:
                networkProvider = "Vina";
                do
                {
                    Console.WriteLine("\nPlease input the phone number (Enter 999 to comeback)");
                    Console.WriteLine("Vina phone number has to start with 088, 091, 094 and has 10 digit");
                    Console.Write("Input number: ");
                    int.TryParse(Console.ReadLine(), out phoneNumber);
                    if (phoneNumber == 999)
                    {
                        break;
                    }
                } while (phoneNumber / 10000000 != 88 && phoneNumber / 10000000 != 91 && phoneNumber / 10000000 != 94 && phoneNumber.ToString().Length != 9);
                break;

            default:
                break;
            }
            //Create NumberModel object and continue to check FengShui
            NumberModel number = new NumberModel
            {
                PhoneNumber     = phoneNumber,
                NetworkProvider = networkProvider
            };

            return(number);
        }