public void Interest(EmpFields emp)
 {
     Console.Write("Enter your Id : ");
     emp.AccId = Convert.ToInt32(Console.ReadLine());
     result    = Search(emp.AccId, con);
     string[] tokens = result.Split(',');
     balance = Convert.ToInt32(tokens[0]);
     if (balance < 0)
     {
         Console.WriteLine(" No record found with this Account Id. Please try again....");
     }
     else
     {
         AccType = tokens[1];
         char[] ch = AccType.ToCharArray();
         AccType = ch[0] + "";
         float simpleInterest = 0;
         if (AccType == "s")
         {
             simpleInterest = (balance * 4 * 1) / 100;
             Console.WriteLine("Interest is: {0} Rs per Year", simpleInterest);
         }
         else if (AccType == "c")
         {
             simpleInterest = (balance * 1 * 1) / 100;
             Console.WriteLine("Interest is: {0} Rs per Year", simpleInterest);
         }
         else
         {
             Console.WriteLine("Interest cannot be appliet on DMAT's Account");
         }
     }
 }
 public void Withdraw(EmpFields emp)
 {
     //int bal = emp.balance;
     Console.Write("Enter your Id : ");
     emp.AccId = Convert.ToInt32(Console.ReadLine());
     result    = Search(emp.AccId, con);
     string[] tokens = result.Split(',');
     balance = Convert.ToInt32(tokens[0]);
     if (balance < 0)
     {
         Console.WriteLine(" No record found with this Account Id. Please try again....");
     }
     else
     {
         Console.WriteLine("Your available balance is : {0}", balance);
         AccType = tokens[1];
         char[] ch = AccType.ToCharArray();
         AccType = ch[0] + "";
         Console.WriteLine("Enter the amount you want to withdraw ");
         int draw = Convert.ToInt32(Console.ReadLine());
         if (AccType == "s")
         {
             if ((balance - draw) < 1000)
             {
                 Console.WriteLine("Minimum Balance in savings account must be 1000 Rs. Please withdraw some less amount.");
             }
             else
             {
                 balance = balance - draw;
             }
         }
         else if (AccType == "c")
         {
             if ((balance - draw) < 0)
             {
                 Console.WriteLine("Minimum Balance in current account must be 0 Rs. Please withdraw some less amount.");
             }
             else
             {
                 balance = balance - draw;
             }
         }
         else
         {
             if ((balance - draw) < -10000)
             {
                 Console.WriteLine("Minimum Balance in current account must be -10000 Rs. Please withdraw some less amount.");
             }
             else
             {
                 balance = balance - draw;
             }
         }
     }
     Update(balance, con, emp.AccId);
 }
 public void OpenAcc(EmpFields emp)
 {
     Console.WriteLine("Enter Name  & Account Type (savings |current | DMAT) :");
     emp.name    = Console.ReadLine();
     emp.AccType = Console.ReadLine();
     Console.WriteLine("Enter starting balance :");
     emp.balance = Convert.ToInt32(Console.ReadLine());
     emp.AccId   = Convert.ToInt32(GetNumber());
     InsertInto(emp, con);
 }
 public void Deposit(EmpFields emp)
 {
     Console.Write("Enter your Account Id : ");
     emp.AccId = Convert.ToInt32(Console.ReadLine());
     result    = Search(emp.AccId, con);
     string[] tokens = result.Split(',');
     balance = Convert.ToInt32(tokens[0]);
     if (balance < 0)
     {
         Console.WriteLine(" No record found with this Account Id. Please try again....");
     }
     else
     {
         Console.WriteLine("Enter the amount you want to deposit ");
         int depo = Convert.ToInt32(Console.ReadLine());
         balance = balance + depo;
         Update(balance, con, emp.AccId);
     }
 }
        public void InsertInto(EmpFields emp, SqlConnection con)
        {
            // employee employe = new employee();

            try
            {
                string s = "insert into employee(id , name , balance , accountType) values(@p1,@p2,@p3,@p4)";
                cmd = new SqlCommand(s, con);
                cmd.Parameters.AddWithValue("@p1", emp.AccId);
                cmd.Parameters.AddWithValue("@p2", emp.name);
                cmd.Parameters.AddWithValue("@p3", emp.balance);
                cmd.Parameters.AddWithValue("@p4", emp.AccType);
                int i = cmd.ExecuteNonQuery();
                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine("Your {0} Account is created with AccountID : {1}", emp.AccType, (55020600 + count));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
 public void Insert(EmpFields emp)
 {
 }
 public void GetDetails(EmpFields emp)
 {
     Console.Write("Enter your Id : ");
     emp.AccId = Convert.ToInt32(Console.ReadLine());
     Display(emp.AccId, con);
 }
Ejemplo n.º 8
0
        public static void Main()
        {
            bool cont = true;

            while (cont)
            {
                Console.WriteLine("Which Framework You want to use:\n1 for ADO.Net \n2 for Entity Framework");
                int framework = Convert.ToInt32(Console.ReadLine());
                if (framework == 1)
                {
                    EmpFields       emp      = new EmpFields();
                    AccountHandling accounts = new AccountHandling();
                    con = accounts.Connect();
top:
                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                    Console.WriteLine("Enter \n 1 To Open new account \n 2 To Display account details \n 3 To Withdraw some amount \n 4 To Deposit money \n 5 To check Interest ");
                    int choice = Convert.ToInt32(Console.ReadLine());
                    if (choice == 1)
                    {
                        accounts.OpenAcc(emp);
                    }
                    else if (choice == 2)
                    {
                        accounts.GetDetails(emp);
                    }
                    else if (choice == 3)
                    {
                        accounts.Withdraw(emp);
                    }
                    else if (choice == 4)
                    {
                        accounts.Deposit(emp);
                    }
                    else if (choice == 5)
                    {
                        accounts.Interest(emp);
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Magenta;
                        Console.WriteLine("You Entered wrong input. Please Try again...");
                        goto top;
                    }
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("Do You want to Continue : Y or N ");
                    char ch = Convert.ToChar(Console.ReadLine());
                    ch = Char.ToUpper(ch);
                    if (ch == 'Y')
                    {
                        goto top;
                    }
                }
                else if (framework == 2)
                {
                    employee emp = new employee();
                    AccountHandlingByEntity accounts = new AccountHandlingByEntity();
                    con = accounts.Connect();
top:
                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                    Console.WriteLine("Enter \n 1 To Open new account \n 2 To Display account details \n 3 To Withdraw some amount \n 4 To Deposit money \n 5 To check Interest ");
                    int choice = Convert.ToInt32(Console.ReadLine());
                    if (choice == 1)
                    {
                        accounts.OpenAcc(emp);
                    }
                    else if (choice == 2)
                    {
                        accounts.GetDetails(emp);
                    }
                    else if (choice == 3)
                    {
                        accounts.Withdraw(emp);
                    }
                    else if (choice == 4)
                    {
                        accounts.Deposit(emp);
                    }
                    else if (choice == 5)
                    {
                        accounts.Interest(emp);
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine("You Entered wrong input. Please Try again...");
                        goto top;
                    }
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("Do You want to Continue : Y or N ");
                    char ch = Convert.ToChar(Console.ReadLine());
                    ch = Char.ToUpper(ch);
                    if (ch == 'Y')
                    {
                        goto top;
                    }
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("Wrong Input. Please try again....");
                }
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Do You want to Switch Framework : Y or N ");
                char ch1 = Convert.ToChar(Console.ReadLine());
                ch1 = Char.ToUpper(ch1);
                if (ch1 != 'Y')
                {
                    cont = false;
                }
            }
        }