Join Dotnetcodes DotnetCodes.com is online Discussion Forum for Software professionals . It lets you find friends around the world and Create professional network that share similar interests as you. Get help on ur projects by industry specialists. Also get answers to all ur technical/placement related querries.Get an edge over others.
Already MemberClick here to login
ASP.net MVC Interview Questions Answers Interview Questions
Serial Number in SSRS Articles
Get Started Developing for Android Apps with Eclipse Articles
How to Print a Crystal Report direct to printer Articles
Razor View Engine Interview Questions Answers Interview Questions
.Net framework 4.0 Interview Questions Answers Interview Questions
SQL server reporting services Interview Questions (SSRS) part 1 Articles
Whats New in ASP.NET 4.0 Part 2 Articles
Difference between Encapsulation and Abstraction Interview Questions
Explaining SDLC -System Development Life Cycle Articles
SPIRE PDF Library Articles
Infosys Interview Questions Interview Questions
Html5 interview questions and answers Interview Questions
Dynamic Menu using HTML List Tag and CSS in ASP.Net Articles
SharePoint 2010 interview Questions Answers Interview Questions
Submit Articles | More Articles..

Bank Application

Posted By: Atul19 On:11/22/2010 7:54:37 AM in:Source Codes Category:CSharp Hits:6614
How to create bank application in c# (console) base application.

Here we are showing u to how to develop Bank Application using c#(console base) here we having following points to create application this are:

1.it has user authentication based on which console based menu will apear

2.it has menus for adding the customers data into database.

3.it has menu for editing the customers data.

4.it has delete menu for customers data.

5.Authorized user has facility of withdraw and dep[osit and check balance facility.

6.Administrator has all facilities.

 *****************start for developing application with code******************

create database to store information

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Threading;


namespace BankApplication
{
public class Program
    {
        public SqlCommand com;
        public SqlConnection con;
        public SqlDataAdapter sda;
        public SqlDataReader sdr;
        public DataSet ds;
        string input = "";
        string customerAccountNo, CustomerName, CustomerAddress,UserName,Password;
    string CustomerName1, CustomerAddress1;
     long Balance;
    long deposit;
   long withdraw;
 
    //public void showdata()
    //{
    //    customerAccountNo = sdr.GetString(0);
    //    CustomerName = sdr.GetString(1);
    //    CustomerAddress = sdr.GetString(2);
    //    Balance = sdr.GetInt64(3);


    //}
   


    public void authentication()
    {
        con = new SqlConnection("Data Source=ATUL\\SQLEXPRESS;Initial Catalog=BankApplication;Integrated Security=true");
        sda = new SqlDataAdapter("select * from customerInformation", con);
        ds = new DataSet();
        sda.Fill(ds, "customerInformation");
        

        Console.ForegroundColor = ConsoleColor.Red;

        Console.BackgroundColor = ConsoleColor.White;
       
        Console.WriteLine("\t\t***************WELCOME TO BANKING APPLICATION***************\n");

        Console.BackgroundColor = ConsoleColor.Black;

        Console.ForegroundColor = ConsoleColor.Gray;
      
        Console.WriteLine("\t\t\t\tPlease Select Your Authority\t\t\t\t");
        Console.ForegroundColor = ConsoleColor.White;
        
        Console.WriteLine("\t\t\t\tA.Admin\t \tB.User\t\t\t\t");
        input = Console.ReadLine();
      
        switch (input)
        {
            case "A":
                input = "Admin";
                Console.Write("\nUserName :");
                  UserName = Console.ReadLine();
                  //Console.Write("UserName :");
                  Console.Write("Password :" );
                  Password = Console.ReadLine();

                //IT IS DEFINE USERNAME AND PASSWORD
                

                  if (UserName.Equals("admin") && Password.Equals("admin"))
                  {
                      Console.ForegroundColor = ConsoleColor.White;
                      Console.WriteLine("\n<<<Please Select Following Menus>>>");
                      Console.WriteLine("\n\t 1.AddCustomer\n\t 2.UpdateCustomer\n\t 3.DeleteCustomer\n\t 4.Exit\n\t");
                      Console.WriteLine("Please Enter Your Choice :--->");
                      input = Console.ReadLine();
                      switch (input)
                      {

                          case "1":
                              input = "AddCustomer";
                              try
                              {


                                  Console.Write("CustomerAccountNo: ");
                                  customerAccountNo = Console.ReadLine();
                                  Console.Write("CustomerName : ");
                                  CustomerName = Console.ReadLine();
                                  Console.Write("CustomerAddress :");
                                  CustomerAddress = Console.ReadLine();
                                  Console.Write("Balance :");
                                  Balance = Convert.ToInt32(Console.ReadLine());

                             
                              try
                              {
                                  string insert = "insert into customerInformation values('" + customerAccountNo + "','" + CustomerName + "','" + CustomerAddress + "'," + Balance + ")";
                                  com = new SqlCommand(insert, con);
                                  con.Open();
                                  com.ExecuteNonQuery();

                                  con.Close();
                                  Console.Write("DATA INSERTTED SUCCESSFULLY!\n");
                                  // Console.WriteLine("THANK YOU FOR USING THE SERVICE!!");
                              }
                              catch (Exception ex)
                              {
                                  Console.Write("Record already Present");

                              }

                          }
                          catch (Exception ex)
                          {
                              Console.WriteLine("Data Not Insert");


                          }

                             

                              

                              break;

                          case "2":
                         if (customerAccountNo != "")
                              {
                              input = "UpdateCustomer";
                              Console.Write("Enter CustomerAccount No :");
                              customerAccountNo = Console.ReadLine();
                             
                                  if (con.State == ConnectionState.Open)
                                      con.Close();
                                  con.Open();
                                  ds.Clear();

                                  com = con.CreateCommand();
                                  com.CommandText = "select * from customerInformation where CustomerAccountNo like '" + customerAccountNo + "%'";
                                  sda.SelectCommand = com;
                                  sda.Fill(ds, "customerInformation");
                                  sdr = com.ExecuteReader();

                                  if (sdr.Read())
                                  {
                                      //customerAccountNo = sdr.GetString(0);
                                      //Console.WriteLine("CustomerAccountNo :" + customerAccountNo);

                                      CustomerName = sdr.GetString(1);
                                      Console.WriteLine("\nCustomerName :" + CustomerName);
                                      CustomerAddress = sdr.GetString(2);
                                      Console.WriteLine("\nCustomerAddress :" + CustomerAddress);
                                      Console.WriteLine("\nUpdate Your Name Or Address");


                                      Console.Write("\nCustomerUpdateName :" + CustomerName1);
                                      CustomerName1 = Console.ReadLine();

                                      Console.Write("\nCustomerUpdateAddress :" + CustomerAddress1);
                                      CustomerAddress1 = Console.ReadLine();

                                      con.Close();

                                  }






                                  else
                                  {
                                      Console.Write("DATA NOT FOUND\n");



                                  }
                            
                              }
                             
     return;

                              try
                              {
                                 // string update = "update customerInformation set customerAccountNo='" + customerAccountNo + "',CustomerName='" + CustomerName + "',CustomerAddress='" + CustomerAddress + "',Balance=" + Balance + "where customerAccountNo=" + customerAccountNo;
                                  string update = "update customerInformation set CustomerName='" + CustomerName1 + "',CusomerAddress='" + CustomerAddress1 + "'where CustomerAccountNo=" + customerAccountNo;
                                  com = new SqlCommand(update, con);
                                  con.Open();
                                  
                                  com.ExecuteNonQuery();
                                  //con.Close();

                                  Console.Write("DATA UPDATTED SUCCESSFULLY");


                              }
                              catch (Exception ex)
                              {
                                  Console.Write("DATA NOT UPDATTED SUCCESSFULLY"+ex.Message);

                              }
                              break;

                                 

                               
                                    

                               


                          case "3":
                              input = "DeleteCustomer";

                              Console.Write("Enter CustomerAccount No :");
                              customerAccountNo = Console.ReadLine();
                              try
                              {
                                  string delete = "delete from customerInformation where customerAccountNo=" + Convert.ToInt32(customerAccountNo);
                                  com = new SqlCommand(delete, con);
                                  con.Open();
                                  char choose = 'N';
                                  try
                                  {
                                      do
                                      {
                                          Console.Write("Are You sure To DeleteCustomer[Y/N] :");
                                          choose = Convert.ToChar(Console.ReadLine());
                                          Console.Out.Close();

                                      }

                                      while (choose == 'N' || choose == 'n');
                                     



                                  }
                                  catch (Exception ex)
                                  {
                                      Console.WriteLine(ex);


                                  }

                                  com.ExecuteNonQuery();
                                  Console.Write("DATA DELETED SUCCESSFULLY\n\n");
                                  //Console.WriteLine("THANK YOU FOR USING THE SERVICE!!");
                              }
                              catch (Exception ex)
                              {

                                  Console.Write("DATA NOT DELETED");
                              }
                              break;


                          
                          case "4":

                              char choice = 'N';
                              try
                              {
                                  do
                                  {
                                      Console.Write("Are You sure To exit?[Y/N] :");
                                      choice = Convert.ToChar(Console.ReadLine());
                                      Console.Out.Close();

                                  }

                                  while (choice == 'N' || choice == 'n');



                              }
                              catch (Exception ex)
                              {
                                  Console.WriteLine(ex);


                              }


                              



                              break;


                          default:
                              Console.WriteLine("Invalid choice");

                              break;

                      }
                  

                  }
                  else
                  {

                      Console.WriteLine("Invalid UserName/Password");
                  }
                  break;

            case"B":
                input = "User";
                Console.Write("\nPlease Enter AccountNo :");
                customerAccountNo = Console.ReadLine();
                bool flag = true;
                int count = ds.Tables["customerInformation"].Rows.Count;
                for (int i = 0; i < count; i++)
                {
                    if (customerAccountNo == ds.Tables["customerInformation"].Rows[i][0].ToString())
                    {
                        flag = true;
                        break;

                    }

                       
                    else
                    {

                        flag = false;
                       // Console.WriteLine("invalid user");
                    }
                
}

                   
                    if (flag)
                    {
                        Console.WriteLine("\n1.withdraw\t2.deposit\t3.check balance\n");
                        input = Console.ReadLine();
                        switch (input)
                        {
                           
                            case"1":
                                input = "withdraw";

                              //Console.Write("Enter CustomerAccount No :");
                              //customerAccountNo = Console.ReadLine();

                              //customerAccountNo = Console.ReadLine();
                              if (con.State == ConnectionState.Open)
                                  con.Close();
                              ds.Clear();


                              com = con.CreateCommand();
                              com.CommandText = "select * from customerInformation where CustomerAccountNo like'" + customerAccountNo + "%'";
                              sda.SelectCommand = com;
                              sda.Fill(ds, "customerInformation");
                              con.Open();
                              sdr = com.ExecuteReader();
                              if (sdr.Read())
                              {

                                  Balance = sdr.GetInt64(3);
                                  Console.WriteLine("Your Current Balance is :" + Balance);


                              }
                              else
                              {
                                  Console.Write("DATA NOT FOUND");

                              }
  con.Close();
                           
                              Console.Write("\nPlease Enter Numbers to withdraw balance :");

                              withdraw = Convert.ToInt64(Console.ReadLine());
                              

                              
                            
                              
if (Balance <= withdraw)
                                  Console.WriteLine("\nInsufficientBalance");
                                else

                              if (withdraw < 0)
                                  Console.WriteLine("\nCannot withdraw");
                               

                           


                                  try
                                  {

                                      string wtdr = "update customerInformation set Balance=Balance-" + (withdraw) + "where customerAccountNo=" + customerAccountNo;
                                      com = new SqlCommand(wtdr, con);
                                      con.Open();
                                      com.ExecuteNonQuery();
                                      Console.WriteLine("\nYour Balance Is Withdraw\n");
                                      if (con.State == ConnectionState.Open)
                                          con.Close();
                                      ds.Clear();


                                      com = con.CreateCommand();
                                      com.CommandText = "select * from customerInformation where CustomerAccountNo like'" + customerAccountNo + "%'";
                                      sda.SelectCommand = com;
                                      sda.Fill(ds, "customerInformation");
                                      con.Open();
                                      sdr = com.ExecuteReader();
                                      if (sdr.Read())
                                      {

                                          Balance = sdr.GetInt64(3);
                                          Console.WriteLine("Now Your Current Balance is :" + Balance);


                                      }
                                      con.Close();




                                  }
                                  catch (Exception ex)
                                  {

                                      ex.ToString();
                                      
                                  }
                             
                               
                              
                              break;

                            case "2":
                                input = "deposit";

                                //Console.Write("Enter CustomerAccountNo :");
                                //customerAccountNo = Console.ReadLine();
                                //customerAccountNo = Console.ReadLine();
                                if (con.State == ConnectionState.Open)
                                    con.Close();
                                ds.Clear();


                                com = con.CreateCommand();
                                com.CommandText = "select * from customerInformation where CustomerAccountNo like'" + customerAccountNo + "%'";
                                sda.SelectCommand = com;
                                sda.Fill(ds, "customerInformation");
                                con.Open();
                                sdr = com.ExecuteReader();
                                if (sdr.Read())
                                {

                                    Balance = sdr.GetInt64(3);
                                    Console.WriteLine("\nYour Current Balance is :" + Balance);


                                }
                                else
                                {
                                    Console.Write("DATA NOT FOUND");

                                }
                                  con.Close();


                                Console.Write("\nPlease enter Numbers to Deposit balance :");
                                deposit = Convert.ToInt64(Console.ReadLine());
                                if (deposit <= 0)
                                    Console.WriteLine("\nCannot Deposit");
                                    
                                else

                                  
                              
                                try
                                {
                                    string dpst = "update customerInformation set Balance =Balance+" + (deposit) + "where customerAccountNo=" + customerAccountNo;
                                    con.Open();
                                    com = new SqlCommand(dpst, con);
                                    com.ExecuteNonQuery();
                                    Console.WriteLine("Amount is Depositted");
                                    if (con.State == ConnectionState.Open)
                                        con.Close();
                                    ds.Clear();


                                    com = con.CreateCommand();
                                    com.CommandText = "select * from customerInformation where CustomerAccountNo like'" + customerAccountNo + "%'";
                                    sda.SelectCommand = com;
                                    sda.Fill(ds, "customerInformation");
                                    con.Open();
                                    sdr = com.ExecuteReader();
                                    if (sdr.Read())
                                    {

                                        Balance = sdr.GetInt64(3);
                                        Console.WriteLine("\nNow Your Current Balance is :" + Balance);


                                    }
                                    con.Close();


                                }
                                catch (Exception ex)
                                {



                                }
                                break;
                            case "3":
                                input = "check balance ";

                                //Console.Write("Please Enter CustomerAccountNo :");
                                //customerAccountNo = Console.ReadLine();
                                if (con.State == ConnectionState.Open)
                                    con.Close();
                                ds.Clear();


                                com = con.CreateCommand();
                                com.CommandText = "select * from customerInformation where CustomerAccountNo like'" + customerAccountNo + "%'";
                                sda.SelectCommand = com;
                                sda.Fill(ds, "customerInformation");
                                con.Open();
                                sdr = com.ExecuteReader();
                                if (sdr.Read())
                                {

                                    Balance = sdr.GetInt64(3);
                                    Console.WriteLine("Your Current Balance is :" + Balance);


                                }
                                else
                                {
                                    Console.Write("DATA NOT FOUND");

                                }
                                break;


                             
                            default:
                                Console.WriteLine("Invalid User");
                                break;



                        }




                   }

               
 
            

               
break;


        }

        Console.ForegroundColor = ConsoleColor.Magenta;
        Console.WriteLine("\n\n\t\t\t\t'THANK YOU' FOR USING THE SERVICE!!");
        Console.ForegroundColor = ConsoleColor.White;



    }



    public static void Main(string[] args)
        {
            Program pp = new Program();
            pp.authentication();



        }
    }
}

 

output will be:

 

 

 


comments powered by Disqus
User Profile
Atul
Web Developer
?????? , India
Email :You must Log In to access the contact details.
Latest Post from :Atul19
Bank Application
View: 6614 | Submitted on: 11/22/2010 7:54:37 AM
How To Decrease Value in Label When enter data in textbox
View: 1758 | Submitted on: 10/15/2010 1:01:53 PM
Asp.net 2.0 interview question and anserws
View: 1898 | Submitted on: 10/15/2010 12:57:09 PM
Submit Articles | All Post of This User..


Advertise About Us Private Policy Terms of use
All rights reserved to dotnetcodes. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks.
Best viewed at 1024 x 768 resolution with Internet Explorer 5.0 or Mozila Firefox 3.5 or Google Crome and higher