Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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();
    }
}


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;


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
Posted

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
 
Share this answer
 
Comments
CareTaker222 14-Apr-15 11:27am    
Hi Sergey! Thank you for your comment.

I want to use that data that was just added on the first page to be sent to the second page for further editing.

The first page is where I create a new client and the second is page is the next step where I create a quote for that specific client that was just added to the database. Sorry I do not know how to explain better what I want to achieve. :) Thank you for the help.
Sergey Alexandrovich Kryukov 14-Apr-15 11:35am    
I think I already answered to this. If you have further concerns, ask some follow-up questions.
—SA
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:
C#
int CQ = NewClient.ClientLoginID;
ClientDetails.ID = CQ;


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:

XML
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:

C#
public static class ClientDetails
{
    public static int ID { get; set; }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900