logo

Implement Window Connections

   

Added on  2022-12-12

11 Pages1346 Words97 Views
 | 
 | 
 | 
STEP 1: IMPLEMENT WINDOW CONNECTIONS
The connection to other screen are made by creating the object of that screen (Window)
and using the ShowDialog method
The following code opens the CompaniesWindow when user selects company from the
navigation
Code:
private void mnuList_Click(object sender, RoutedEventArgs e)
{
CompaniesWindow cw = new CompaniesWindow();
cw.ShowDialog();
}
In the same fashion other windows are also connected based on the user action such
as click of a button the Object for that window is create and that window is set to be
display.
When user click on Companies the new CompaniesWIndow Object is create and
displayed
Implement Window Connections_1

STEP 2: IMPLEMENT C# CODE – ADD COMPANY
An Array list of companies objects is used to store the companies’ data. To make it
accessible throughout the application the Array List is defined in the Main Window of the
application.
Code:
public ArrayList companies = new ArrayList();
The field validation is done to check for empty values in required fields and appropriate
error messages are shown
Code:
if (this.txtlblNewCompanyName.Text.Trim().Equals(""))
{
MessageBox.Show("Enter company name", "Error");
return;
}
After the field validation object of the Companies class is created based on the input
values in the textboxes and added to the Array list.
Company cmp = new Company(this.txtlblNewCompanyName.Text,
this.txtNewAddressLine1.Text, this.txtNewFirstName.Text,
this.txtNewLastName.Text, this.txtNewSuburbCity.Text,
Implement Window Connections_2

this.txtNewPhoneNumber.Text, this.txtNewPostcode.Text, this.txtNewState.Text,
this.txtNewEmail.Text, this.txtNewCountry.Text, this.txtNewWebsite.Text);
((MainWindow)Application.Current.MainWindow).companies.Add(cmp);
The Status bar on the main window is also updated with added status
Code:
((MainWindow)Application.Current.MainWindow).lblStatudBar.Content = "Company
Added";
Window that accepts company details
Implement Window Connections_3

Company gets added and shown in the list
STEP 3: IMPLEMENT C# CODE – LIST/BROWSE ALL COMPANIES
The data grid is used to display the list of companies the binding is done in the XAML
Code:
<DataGrid x:Name="companytbl" Grid.ColumnSpan="6" HorizontalAlignment="Center"
CanUserAddRows="True" Height="291" Margin="14,101,6,0" VerticalAlignment="Top"
Width="772" SelectionChanged="companytbl_SelectionChanged">
<DataGrid.Columns>
<DataGridTextColumn Header="Company Name" IsReadOnly="True"
Binding="{Binding Path=companyName}"
Width="130">
</DataGridTextColumn>
<DataGridTextColumn Header="Email" IsReadOnly="True"
Binding="{Binding Path=email}" Width="130">
</DataGridTextColumn>
<DataGridTextColumn Header="Website" IsReadOnly="True"
Binding="{Binding Path=website}" Width="130">
</DataGridTextColumn>
<DataGridTextColumn Header="Phone Number" IsReadOnly="True"
Binding="{Binding Path=phonenumber}" Width="130">
</DataGridTextColumn>
<DataGridTextColumn Header="Contact Person" IsReadOnly="True"
Binding="{Binding Path=contactName}" Width="250">
Implement Window Connections_4

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents