issac754870110 2016-06-04 14:06 采纳率: 0%
浏览 1094
已结题

关于WPF窗体间传值的问题……我把代码放上来……

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;
        }
    }
  • 写回答

1条回答 默认 最新

  • devmiao 2016-06-04 15:27
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog