2016-11-08 41 views
-1

here when I press login登录形式使用收集的列表方法

and here when I press yes

正在使用C#做一个ATM项目,它是从我的老师需要使用数据库来完成与这项任务,所以我创建了包含一类列表中存储所有的数据,而创建一个新的帐户,但问题是,我不能使用数据登录(我不知道如何做布尔编码的事情,以确定如果该项目是在列表中)

注意:在登录时你应该输入你的名字和密码来登录

这里是我创建账户表单代码

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) 
    { 

    } 
} 

,这是我的登录表单

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

正确的地方“我不知道如何做布尔编码的事情“?在所有这些代码中,哪里有问题?你试图做什么,你怎么卡住?你做了什么样的尝试?你看到了什么错误? – David

+0

@大卫我认为艾哈迈德试图回答你的问题。艾哈迈德,请使用'@'来引用其他用户! – meJustAndrew

+0

@AhmedAlnakhi:我不知道这里的困惑在哪里,但*你*是描述问题的人* * * ... – David

回答

0

这个问题缺少很多必要的信息。目前还不清楚你需要做什么。

但是,这就是说,如果你需要存储数据,但你不允许使用数据库,你可以把它放到一个文本文件中。你甚至可以加密数据,使其更“安全”。

如果您只需要为每个用户会话保存数据,那么在首次运行包含用户的类为空的应用程序时,无关紧要。事实上,它让事情变得更容易,因为第一次运行应用程序知道您的用户类将为空。

我建议你有一个包含List<UserClass> usersList的登录表单。当您的用户点击登录,首先检查列表中是否包含任何条目:

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

如果没有值显示在列表中的表单来创建新用户。当您验证了创建用户表单中的值后,将您的UserClass的新实例添加到列表中,并显示登录表单,无论这可能是什么。

我也建议你阅读.NET和C#的众多的入门教程之一,因为这可能不是问你的意思等基本问题:)