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
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](/_next/image/?url=https%3A%2F%2Fdesklib.com%2Fmedia%2Fimages%2Fqh%2F10d2598b9c764b62b66e4374b2ab8bc3.jpg&w=3840&q=10)
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,
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](/_next/image/?url=https%3A%2F%2Fdesklib.com%2Fmedia%2Fimages%2Fjk%2F0a870a0c1c1347a2aa62f5f35c9503f7.jpg&w=3840&q=10)
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
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](/_next/image/?url=https%3A%2F%2Fdesklib.com%2Fmedia%2Fimages%2Fwu%2F1797c87fdde44ce8ae8fe381b696d9a3.jpg&w=3840&q=10)
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">
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](/_next/image/?url=https%3A%2F%2Fdesklib.com%2Fmedia%2Fimages%2Fns%2Fce615f671c9d4cef8c1ce77757377ed9.jpg&w=3840&q=10)
End of preview
Want to access all the pages? Upload your documents or become a member.
Related Documents