2016-11-08 40 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#的衆多的入門教程之一,因爲這可能不是問你的意思等基本問題:)