将数据从一个窗口发送到另一个窗口 [英] Sending data from one window to another

查看:110
本文介绍了将数据从一个窗口发送到另一个窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Linq-to-SQL将文本框中的数据添加到pgAddClients窗口的数据表中。



现在,只要我的Click事件发生在我的按钮运行以保存我的表中的数据,一个新窗口打开,旧窗口关闭。



对于所有编码很抱歉,我只是希望它可能有所帮助。



我的保存编码:



I am using Linq-to-SQL for adding data from textboxes into a data table on my pgAddClients window.

Now as soon as my Click event on my button runs to save the data in my table, a new window opens and the old one closes.

Sorry for all the coding, I just hope it might help some way.

My save coding:

public void btnSaveAndCreateQuote_Click(object sender, RoutedEventArgs e)
{

    int CurrentEmployee = Credentials._eld.LoginID;

    tblClientLoginDetail NewClient = new tblClientLoginDetail();
    NewClient.ClientEmailAddress = txtEmailAddress.Text;
    NewClient.ClientPassword = pbPassword.Password;
    NewClient.ClientIDNumber = txtIDNumber.Text;
    NewClient.ClientName = txtName.Text;
    NewClient.ClientSurname = txtSurname.Text;
    NewClient.ClientWorkAddress = txtHomeAddress.Text;
    NewClient.ClientWorkNumber = txtTelephoneNumber.Text;
    NewClient.ClientCity = txtCity.Text;
    NewClient.ClientProvinceCode = cmbProvinceCode.Text;
    NewClient.ClientCompanyName = txtCompanyName.Text;
    NewClient.ClientCompanyLogo = _img;
    NewClient.EmployeeID = CurrentEmployee;

    using (DataClassesDataContext DC = new DataClassesDataContext())
    {
        if (DC.tblClientLoginDetails.Any(i => i.ClientEmailAddress.ToLower() == txtEmailAddress.Text.ToLower()))
        {
            pgClientExists pgCE = new pgClientExists();
            pgCE.ShowDialog();
            txtEmailAddress.Clear();
            return;
        }
        DC.tblClientLoginDetails.InsertOnSubmit(NewClient);
        DC.SubmitChanges();


        btnClearAccountInformation_Click(null, null);
        btnClearGeneralInformation_Click(null, null);
        btnDeletePicture_Click(null, null);

        pgClientAdded pgCA = new pgClientAdded();
        pgCA.Show();
        CloseAddClientWindow();
        pgCreateQuote pgCQ = new pgCreateQuote();
        pgCQ.ShowDialog();
    }
}





问题是我现在需要查看已添加 的确切数据,并继续在新的 pgCreateQuote 窗口中向该表格列添加更多信息。我没有收到任何错误,因为我还不知道怎么做。



如果有人有任何想法或需要更多信息,我会更愿意提供它。



更好地解释我的问题:如何从一个窗口中选择添加到我的数据表中的行并继续添加更多数据不使用DataGrid在新窗口中的那一行?我需要在下一页上为用户预先选择刚刚添加的那一行数据。



这是编码,我可以调用一些在第一个窗口中使用的项目,以及可能在我的第一个窗口中访问我用于将数据保存到数据表的方法 pgAddClients。





The problem is that I now need to view that exact data that was just added and continue to add more info to that table column on the new pgCreateQuote window. I am not getting any errors because I have no idea how to do this yet.

If anyone has any ideas or need any more info, I would be more than willing to provide it.

To explain my question a bit better: how can I select the row that was added into my data table from one window and continue to add more data to that row in a new window without using a DataGrid? I need to have that row of data that was just added, pre-selected for the user on the next page.

Here is coding where I can call some of the items that was used in the first window, as well as maybe access the method that I used to save my data to my data table in my first window pgAddClients.

pgAddClients vcInfo = (pgAddClients)Application.Current.MainWindow;





现在我想要在我的新页面 pgCreateQuote 的标签内显示客户的名字(刚刚在我的上一页/ pgAddClient 中添加)。



我的表名是 tblClientLoginDetails



Now I want to show the client's name(that was just added in my previous page/ pgAddClient) inside a label on my new page pgCreateQuote.

My table name is tblClientLoginDetails

推荐答案

请参阅我的提示和技巧文章一次回答的许多问题 - Windows窗体或WPF Windows之间的协作



这不太好清楚为什么要显示刚添加的数据,但可能你可以在首先添加数据的方法中做到这一点。如果您的问题是分离在不同块中添加的数据并分别直观地呈现这些块,您可能会想到一些不同的表示控件,例如某事物的树视图。如果你更详细地解释一下你想得到什么(以及为什么),我们可以讨论它。



-SA
Please see my Tips&Tricks article Many Questions Answered at Once — Collaboration between Windows Forms or WPF Windows.

It is not quite clear why showing data which is just added, but probably you can do it in the method which adds data in first place. If your problem is isolation of pieces of data added in different chunks and visually presenting these chunks separately, you may think of some different presentation control, such as a tree view of something. We can discuss it if you explain what you want to get (and why) in more detail.

—SA


我想通了。



我需要的只是创建一个int和一个新的公共类。我将int等于新创建的 ClientLoginID 并将公共类等同于int。



第一个窗口编码:

I figured it out.

All I needed was to create an int and a new public class. I equaled the int to the newly created ClientLoginID and equaled the public class to the int.

First window coding:
int CQ = NewClient.ClientLoginID;
ClientDetails.ID = CQ;





我现在可以在第二个窗口中调用该公共类并选择 ClientLoginID 等于类 ID ,我有我刚刚添加的新客户端。 :)



这是我第二个窗口的编码:





I can now call that public class in the second window and select the ClientLoginID that equals the class ID and there I have my new client that I JUST added. :)

Here is the coding in my second window:

int CD = ClientDetails.ID;
using (DataClassesDataContext DC = new DataClassesDataContext())
{
    tblClientLoginDetail tblCLD = DC.tblClientLoginDetails.Single<tblClientLoginDetail>
        (i => i.ClientLoginID == CD);
    lblSelectedUser.Content = tblCLD.ClientName + " - " + tblCLD.ClientSurname;
}





我的班级编码可能需要它的任何人:





My class coding for anyone that might need it:

public static class ClientDetails
{
    public static int ID { get; set; }
}


这篇关于将数据从一个窗口发送到另一个窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆