-1

here when I press login

and here when I press yes

am doing an ATM project using C# and it was required from my teacher to complete this task with out using a database so I created a class which contains a list to store all the data in while creating a new account, but the problem is that I cant use the data for login (I don't know how to do the bool coding thing to determines if the item is in the list)

Note:in login you should enter your name and pin code to login

here is my create account form code

public partial class NewAccountForm : Form
{
    public NewAccountForm()
    {
        InitializeComponent();
    }
    Accounts account1;


    private void btnCreate_Click(object sender, EventArgs e)
    {
    }

    private void button1_Click(object sender, EventArgs e)
    {

    }

    private void button2_Click(object sender, EventArgs e)
    {
        Form1 login = new Form1();
        this.Hide();
        login.Show();
    }

    private void btncreate_Click(object sender, EventArgs e)
    {


        int interest = 0;
        char type = '0';
        double amount = 0 ;
        double balance = 0;

        switch (cboType.SelectedIndex)
        {
            case 0: type = '1'; break;

            case 1: type = '2'; break;

        }
        Saveing account1 = new Saveing(interest, txtName.Text, txtContact.Text,
            txtpinCode.Text, type, amount,balance);

        Data.CSaveing.Add(account1); //SList shows because its static if remove static will not appears
    }

    private void NewAccountForm_Load(object sender, EventArgs e)
    {

    }
}

and this is my login form

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
    Data Accounts;
    bool validCode = false;

    private void Form1_Load(object sender, EventArgs e)
    {

    }

    private void label1_Click(object sender, EventArgs e)
    {

    }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {

    }

    private void button1_Click(object sender, EventArgs e)
    {

        Accounts.name = txtname.Text;
        Accounts.code = txtCode.Text;

        if (string.IsNullOrWhiteSpace(txtname.Text))
        {
            MessageBox.Show("Please Type your full name");
        }
        if (string.IsNullOrWhiteSpace(txtCode.Text))
        {
            MessageBox.Show("Please Enter a correct account Pin Code");
        }
        else if ((Accounts.name == txtname.Text)) ;
        else if ((Accounts.code != txtCode.Text)) ;
        {
            int i;
            progressBar1.Maximum = 100;
            progressBar1.Minimum = 0;
            progressBar1.Step = 1;
            timer1.Start();

            for (i = 0; i <= 50; i++)

                progressBar1.Value = i;

        }
    }

    private void button2_Click(object sender, EventArgs e)
    {
        NewAccountForm naf = new NewAccountForm();
        this.Hide();
        naf.Show();
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        progressBar1.PerformStep();
        if (progressBar1.Value == 99)
        {
            LoginForm login = new LoginForm();
            this.Hide();
            login.Show();
        }
    }

    private void label3_Click(object sender, EventArgs e)
    {

    }

    private void label4_Click(object sender, EventArgs e)
    {

    }
}
  • 2
    What do you mean by "I don't know how to do the bool coding thing"? In all of this code, where specifically are you having a problem? What specifically are you attempting to do and how are you stuck? What attempt have you made and what error are you seeing? – David Nov 08 '16 at 16:03
  • @David I think that Ahmed tried to answer your questions. Ahmed, please use `@` to refer to the other users! – meJustAndrew Nov 08 '16 at 16:15
  • @AhmedAlnakhi: I'm not sure where the confusion is here, but *you* are the one describing a problem to *us*... – David Nov 08 '16 at 16:17
  • am stuck in form1 button1_Click I cant get the name and pin code the has been created in NewAccountForm @david – Ahmed Alnakhi Nov 08 '16 at 16:20
  • @AhmedAlnakhi: Can you be more clear about what exactly you're trying? Where are those "name" and "pin code" values stored that you're trying to access? Aren't you just adding them to a collection in `Data.CSaveing`? So aren't they in that collection? – David Nov 08 '16 at 16:24
  • @David yes they are stored in Data.CSaveing but I cant use them for login I will add pics so it be more clear. thank you in advance – Ahmed Alnakhi Nov 08 '16 at 16:27
  • @AhmedAlnakhi: The pictures you added are just of your interface. They don't explain anything about the problem. *Why* can't you use those values for login? What *actually prevents you* from doing that? We're trying to help, but you have to be able to at least describe the problem. Perhaps this is a good opportunity for you to familiarize yourself with the concept of debugging, which allows you to step through the code line by line as it executes and observe the actual behaviors and values. – David Nov 08 '16 at 16:31
  • @David can you check the pictures now please if you could help me BTW am a beginner on C# – Ahmed Alnakhi Nov 08 '16 at 16:38
  • @AhmedAlnakhi: So you're getting a `NullReferenceException`. First hit when searching that on Google: http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it – David Nov 08 '16 at 18:08

1 Answers1

0

This question is missing a lot of necessary information. It isn't clear at all what you are required to do.

However, that said, if you need to store the data but you are not allowed to use a database, you could put it into a text file. You could even encrypt the data to make it more "secure".

If you only need to hold the data per user session, then it doesn't matter when you first run the application that the class containing your users is empty. In fact it makes things easier because the first time you run the application you know that your user class will be empty.

I suggest that you have a login form containing a List<UserClass> usersList. When your user clicks login, first check whether the list contains any entries:

if(usersList.Any()) { ... }

If there are no values in the list show a form to create a new user. When you've validated the values in the create user form add a new instance of your UserClass to the List, and show the logged in form, whatever that may be.

I also suggest you read one of the many introductory tutorials on .NET and C# because this probably isn't the right place to ask such basic questions :)