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.Shapes;
using System.Data.SqlClient;
using System.Data;
using BankMngSystem.Module;
namespace BankMngSystem.Module
{
///
/// Login.xaml 的交互逻辑
///
public partial class Login : Window
{
public string PbAn{ get; set; }
public string[] tempAN = new string[50];//此处需根据需求增加temp上限
public string[] tempPW = new string[50];//此处需根据需求增加temp上限
private int count = 0;
public Login()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
int j = 0;
Button btn = sender as Button;
switch (btn.Content.ToString())
{
//开始用户登录功能
case "登录":
try
{
int i = 0;
using (var context = new BankDbEntities())
{
var q = from t in context.Account
where t.AccountNum != null
select t;
foreach (var v in q)
{
tempAN[i] = v.AccountNum;
tempPW[i] = v.Password;
if (tempAN[i] == TextBoxAccount.Text.ToString())
{
if (tempPW[i] == TextBoxPassWord.Text.ToString())
{
break;//在这里break,阻止遍历继续
}
else if (count < 5)
{
MessageBox.Show("密码错误,还可输入" + (5 - count).ToString() + "次");
}
}
else
j++;//这是第(j+1)行数据
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
this.PbAn = tempAN[0];
DepositNDraw DND = new DepositNDraw();
DND.Show();
MessageBox.Show(PbAn);//输入正确的数会直接变为tempAN[0]
break;
case "退出":
App.Current.Shutdown();
break;
}
count++;//c#计数器,记得将count写在按钮最外面一圈代码里
}
}
}
↑上面这是我的登录界面
↓下面这个是操作界面,还没写完,打算把登录界面的账号传到操作界面,在textblock里显示。
public partial class DepositNDraw : Window
{
public DepositNDraw()
{
InitializeComponent();
this.SourceInitialized += Login_SourceInitialized;
}
private void Login_SourceInitialized(object sender, System.EventArgs e)
{
Login Login = new Login();
TextBlockAN.Text = Login.PbAn;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Button btn = sender as Button;
switch (btn.Content.ToString())
{
case "取款":
//Deposit.Visibility = Visibility.Hidden;
break;
case "存款":
//Deposit.Visibility = Visibility.Visible;
break;
case "退出":
App.Current.Shutdown();
break;
}
}