Пример #1
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            SqlConnection condatabase = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Sherif\Documents\Test.mdf;Integrated Security=True;Connect Timeout=30");

            SqlDataReader reader = null;


            condatabase.Open();

            SqlCommand cmd = condatabase.CreateCommand();

            cmd.CommandText = "select * from Customer";
            reader          = cmd.ExecuteReader();

            while (reader.Read())
            {
                if (txtID.Text == reader.GetString(0) && txtPass.Text == reader.GetString(3))
                {
                    Program.logged_in.ID = reader.GetString(0);


                    Program.logged_in.First_Name = reader.GetString(1);

                    Program.logged_in.Last_Name = reader.GetString(2);

                    Program.logged_in.Password = reader.GetString(3);



                    SqlConnection condatabase2 = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Sherif\Documents\Test.mdf;Integrated Security=True;Connect Timeout=30");

                    SqlDataReader reader2 = null;


                    condatabase2.Open();


                    SqlCommand cmd2 = condatabase2.CreateCommand();
                    cmd2.CommandText = "select * from Account";
                    reader2          = cmd2.ExecuteReader();

                    while (reader2.Read())
                    {
                        if (reader2.GetString(0) == Program.logged_in.ID)
                        {
                            if (reader2.GetString(2) == "Saving")
                            {
                                SavingAccount sa = new SavingAccount(reader2.GetDouble(3), reader2.GetString(1));
                                sa.Set_LastCheched_Date(reader2.GetDateTime(6));

                                Program.logged_in.sv.Add(sa);
                            }
                            else if (reader2.GetString(2) == "Checking")
                            {
                                CheckingAccount ca = new CheckingAccount(reader2.GetDouble(3), reader2.GetString(1), reader2.GetDouble(5));
                                Program.logged_in.Check.Add(ca);
                            }
                            else if (reader2.GetString(2) == "Loan")
                            {
                                Loan La = new Loan(reader2.GetDouble(3), reader2.GetString(1), reader2.GetDouble(4));
                                Program.logged_in.Looan.Add(La);
                            }
                        }
                    }


                    condatabase2.Close();
                    condatabase.Close();


                    AccountsMenu am = new AccountsMenu();
                    am.Show();
                    this.Hide();
                    return;
                }
            }
            timer1.Start();
            pictureBox3.Visible = true;
        }
Пример #2
0
        public void Get_cusData()//Get customer data from table
        {
            Customer obj = new Customer();

            SqlDataReader reader = null;

            condatabase1.Open();
            SqlCommand cmd1 = condatabase1.CreateCommand();

            cmd1.CommandText = "select * from Customer";
            reader           = cmd1.ExecuteReader();
            while (reader.Read())
            {
                if (ID_txt.Text == reader.GetString(0))
                {
                    idtxt.Text    = reader.GetString(0);
                    Fnametxt.Text = reader.GetString(1);
                    Lnametxt.Text = reader.GetString(2);
                    Passtxt.Text  = reader.GetString(3);

                    SqlConnection condatabase2 = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Sherif\Documents\Test.mdf;Integrated Security=True;Connect Timeout=30");
                    SqlDataReader reader2      = null;
                    condatabase2.Open();
                    SqlCommand cmd2 = condatabase2.CreateCommand();
                    cmd2.CommandText = "select * from Account";
                    reader2          = cmd2.ExecuteReader();
                    while (reader2.Read())
                    {
                        if (reader2.GetString(0) == ID_txt.Text)
                        {
                            if (reader2.GetString(2) == "Saving")
                            {
                                SavingAccount sa = new SavingAccount(reader2.GetDouble(3), reader2.GetString(1));

                                Saving_list.Add(sa);
                            }
                            else if (reader2.GetString(2) == "Checking")
                            {
                                CheckingAccount ca = new CheckingAccount(reader2.GetDouble(3), reader2.GetString(1), reader2.GetDouble(5));
                                Checking_list.Add(ca);
                            }
                            else if (reader2.GetString(2) == "Loan")
                            {
                                Loan La = new Loan(reader2.GetDouble(3), reader2.GetString(1), reader2.GetDouble(4));
                                Loan_list.Add(La);
                            }
                        }
                    }


                    condatabase2.Close();
                    //display data of customer in list view
                    for (int i = 0; i < Saving_list.Count; i++)
                    {
                        metroListView1.Items.Add("Account Type : " + "Saving Account");
                        metroListView1.Items.Add("ID : " + Saving_list[i].get_ID());
                        metroListView1.Items.Add("Balance : " + Convert.ToString(Saving_list[i].get_Balance()));
                        metroListView1.Items.Add("------------------");
                    }
                    for (int i = 0; i < Checking_list.Count; i++)
                    {
                        metroListView1.Items.Add("Account Type : " + "Checking");
                        metroListView1.Items.Add("ID : " + Checking_list[i].get_ID());
                        metroListView1.Items.Add("Balance : " + Convert.ToString(Checking_list[i].get_Balance()));
                        metroListView1.Items.Add("------------------");
                    }
                    for (int i = 0; i < Loan_list.Count; i++)
                    {
                        metroListView1.Items.Add("Account Type : " + "Loan Account");
                        metroListView1.Items.Add("ID : " + Loan_list[i].get_ID());
                        metroListView1.Items.Add("Balance : " + Convert.ToString(Loan_list[i].get_Balance()));
                        metroListView1.Items.Add("------------------");
                    }
                }
            }

            condatabase1.Close();
        }