Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 多个foreach传递到不同的类列表_C#_Wpf - Fatal编程技术网

C# 多个foreach传递到不同的类列表

C# 多个foreach传递到不同的类列表,c#,wpf,C#,Wpf,我正在用C#WPF编写一个“银行应用程序”,在那里我遇到了错误:CS0052 可访问性不一致:字段类型“列表”较少 可访问字段“Customer.CustomerAccountsList”以外的字段 这个想法是,方法bool dosethisaccountexisted()应该逐个检查所有客户,看看他/她的帐户是否与即将创建的帐户具有相同的数据 但是CustomerAccountsList必须是公共的,或者dosethisaccountexisted()无法访问帐户数据 如何修复此错误 //ma

我正在用C#WPF编写一个“银行应用程序”,在那里我遇到了错误:CS0052

可访问性不一致:字段类型“列表”较少 可访问字段“Customer.CustomerAccountsList”以外的字段

这个想法是,方法
bool dosethisaccountexisted()
应该逐个检查所有客户,看看他/她的帐户是否与即将创建的帐户具有相同的数据

但是
CustomerAccountsList
必须是公共的,或者
dosethisaccountexisted()
无法访问帐户数据

如何修复此错误

//main window

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Uppgift2
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        public List<Customer> ListOfAllCustomers = new List<Customer>();

        public bool Login(string fornamn, string efternamn, string pin)
        {
            foreach (Customer c in ListOfAllCustomers)
            {
                if (c.firstname == fornamn && c.lastname == efternamn && c.pinKod == pin)
                {
                    MessageBox.Show("Login succesfull. Welcome " + c.firstname + " " + c.lastname);
                    WindowAccountOperations LoggedInUser = new WindowAccountOperations();
                    LoggedInUser.ShowDialog();
                    return true;
                }
                else
                {
                    MessageBox.Show("Det finns inte ett sånt användare. Kontrolera användarnamn och pin");
                    return false;
                }
            }
            return false;
        }

        //Customer pin could be remade into a rondom generator with an if() that forces it to be a four digit number 
       /* 
        *   Random randomPin = new Random();
            randomPin.Next(x, y);

            if(randomPin.ToString().Length!=4)
             {

             }
      */



        public bool CreateNewCustomer(string fornamn, string efternamn, string telefon, string customerAdress, string customerPin)
        { 
            //Is there already such customer?
            foreach (Customer c in ListOfAllCustomers)
            {
                if ((c.firstname == fornamn && c.lastname == efternamn && c.adress == customerAdress))
                {
                    MessageBox.Show("Kunden med ett sånt förnamn, efternamn och adress redan finns");
                    return false;
                }

                if(c.pinKod == customerPin)
                {
                    MessageBox.Show("Kunden med ett sånt pinkod redan finns");
                    return false;
                }
                else
                {
                    ListOfAllCustomers.Add(new Customer(TBFirstNameNyKund.Text, TBSecondNameLogin.Text, TBTelNyKund.Text, TBAdressNyKund.Text, TBPinNyKund.Text));
                    MessageBox.Show("Registration complete. Du kan nu logga in");

                    TBFirstNameNyKund.Clear(); TBSecondNameLogin.Clear(); TBAdressNyKund.Clear(); TBPinNyKund.Clear();//clear login textboxes
                    return true;
                }
            }
            return false;
        }

        public bool DoseThisAccountExistAlready(string kontoNummer, string kontotyp)
        {
            foreach (Customer c in ListOfAllCustomers )
            {
                foreach(Account a in c.CustomerAccountsList)
                {

                    if(a.accountType==kontotyp)//Does customer c try to create another type of account he already has?
                    {
                        return true;
                    }

                    if(a.accountNumber==kontoNummer)
                    {
                        return true;
                    }

                }
                return false;
            }

            return false;
        }

        private void ButtonLogin_Click(object sender, RoutedEventArgs e)
        {
            Login(TBFirstNameLogin.Text, TBSecondNameLogin.Text, TBPinLogin.Text);
        }

        private void ButtonSkapaKund_Click(object sender, RoutedEventArgs e)
        {
            CreateNewCustomer(TBFirstNameNyKund.Text, TBSecondNameNyKund.Text, TBTelNyKund.Text, TBAdressNyKund.Text, TBPinNyKund.Text);
        }
    }
}

//customer class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Uppgift2
{
  public class Customer
  {
    public string adress;
    public string celphone;
    public string firstname;
    public string lastname;
    public string pinKod;

    public List<Account> CustomerAccountsList = new List<Account>();//Error apears here. 



    public Customer(string fname,string lname, string tel, string    customerAdress,string customerPin)
    {
        adress = customerAdress;
        celphone = tel;
        firstname = fname;
        lastname = lname;
        pinKod = customerPin;
    }

  }
}

//account base class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Uppgift2
{
     abstract class Account   //The abstract modifier indicates that the thing being modified has a missing or incomplete implementation=base class for other classes
    {

        public double payoutAmmount;
        protected double payoutTax;
        public bool creditPosible;

        public string accountNumber;
        public string accountType;
        public double balance;
        protected double interest; //customer shouldent be able to modify interest % 


        //constructor
        public Account(string kontoNummer, double KontoStartsaldo,string kontoTyp, double ranta, bool finsdetkredit,double uttagPris)
        {
            accountNumber = kontoNummer;
            balance = KontoStartsaldo;
            accountType = kontoTyp;
            creditPosible = finsdetkredit;
            payoutTax = uttagPris;
        }

        public double InsertMoney(int chosenAccount, double payout)  //int chosenAccount becouse i thought to use a combo box index
        {
            payoutAmmount = payout;

            balance = balance - payout + (payout * payoutTax);
            return balance;  

        }
    }
}
//主窗口
使用制度;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Navigation;
使用System.Windows.Shapes;
命名空间Uppgift2
{
/// 
///MainWindow.xaml的交互逻辑
/// 
公共部分类主窗口:窗口
{
公共主窗口()
{
初始化组件();
}
public List ListOfAllCustomers=new List();
公共bool登录(字符串fornamn、字符串efternamn、字符串pin)
{
foreach(所有客户列表中的客户c)
{
if(c.firstname==fornamn&&c.lastname==efternamn&&c.pinKod==pin)
{
MessageBox.Show(“登录成功。欢迎”+c.firstname+“”+c.lastname);
WindowAccountOperations LoggedInUser=新的WindowAccountOperations();
LoggedInUser.ShowDialog();
返回true;
}
其他的
{
MessageBox.Show(“Det finns inte et sånt användare.Kontrolera användarnam och pin”);
返回false;
}
}
返回false;
}
//可以将客户pin重新制作成rondom生成器,并使用if()强制其为四位数
/* 
*Random randomPin=新的Random();
下一步(x,y);
if(randomPin.ToString().Length!=4)
{
}
*/
public bool CreateNewCustomer(字符串fornamn、字符串efternamn、字符串telefon、字符串CustomerAddress、字符串customerPin)
{ 
//已经有这样的客户了吗?
foreach(所有客户列表中的客户c)
{
if((c.firstname==fornamn&&c.lastname==efternamn&&c.address==customerAddress))
{
MessageBox.Show(“Kunden med ett sånt förnamn,efternamn och地址:redan finns”);
返回false;
}
如果(c.pinKod==customerPin)
{
MessageBox.Show(“Kunden med ett sånt pinkod redan finns”);
返回false;
}
其他的
{
添加(新客户(TBFirstNameNyKund.Text、TBSecondNameLogin.Text、TBTelNyKund.Text、tbaddressnykund.Text、TBPinNyKund.Text));
MessageBox.Show(“注册完成,Du kan nu logga in”);
TBFirstNameNyKund.Clear();TBSecondNameLogin.Clear();tbaddressnykund.Clear();TBPinNyKund.Clear();//清除登录文本框
返回true;
}
}
返回false;
}
已存在公共bool dosethisaccounted(字符串kontoNummer,字符串kontotyp)
{
foreach(所有客户列表中的客户c)
{
foreach(c.CustomerAccountsList中的帐户a)
{
如果(a.accountType==kontotyp)//客户c是否尝试创建他已经拥有的另一种类型的帐户?
{
返回true;
}
如果(a.accountNumber==Kontonumer)
{
返回true;
}
}
返回false;
}
返回false;
}
私有无效按钮登录单击(对象发送者,路由目标)
{
登录名(TBFirstNameLogin.Text、TBSecondNameLogin.Text、TBPinLogin.Text);
}
私有无效按钮单击(对象发送者,路由目标e)
{
CreateNewCustomer(TBFirstNameNyKund.Text、TBSecondNameNyKund.Text、TBTelNyKund.Text、tbaddressnykund.Text、TBPinNyKund.Text);
}
}
}
//客户类别
使用制度;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
命名空间Uppgift2
{
公共类客户
{
公共字符串地址;
公用电话;
公共字符串名;
公共字符串lastname;
公共字符串pinKod;
public List CustomerAccountsList=new List();//此处显示错误。
公共客户(字符串fname、字符串lname、字符串tel、字符串CustomerAddress、字符串customerPin)
{
地址=客户地址;
电话;
firstname=fname;
lastname=lname;
pinKod=客户品;
}
}
}
//帐户基类
使用制度;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
命名空间Uppgift2
{
抽象类帐户//抽象修饰符表示正在修改的对象缺少或不完整的实现=其他类的基类
{
公开双倍支付;
受保护的双重支付税;
公信力强;
公共字符串accountNumber;
公共字符串accountType;
公共双平衡;
受保护的双重利益;//客户应