Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
881ff27
commit f8be93e
Showing
8 changed files
with
285 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<Page x:Class="IoT1.View.AddUserPage" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:IoT1.View" | ||
mc:Ignorable="d" | ||
d:DesignHeight="450" d:DesignWidth="800" | ||
Title="AddUserPage"> | ||
|
||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto"/> | ||
<RowDefinition Height="Auto"/> | ||
<RowDefinition Height="Auto"/> | ||
<RowDefinition Height="Auto"/> | ||
<RowDefinition Height="Auto"/> | ||
<RowDefinition Height="Auto"/> | ||
<RowDefinition Height="Auto"/> | ||
</Grid.RowDefinitions> | ||
|
||
<Label Grid.Row="0" Content="First Name:" Margin="10"/> | ||
<TextBox Grid.Row="0" Name="FirstNameTextBox" Margin="10" Width="200"/> | ||
|
||
<Label Grid.Row="1" Content="Last Name:" Margin="10"/> | ||
<TextBox Grid.Row="1" Name="LastNameTextBox" Margin="10" Width="200"/> | ||
|
||
<Label Grid.Row="2" Content="Agent ID:" Margin="10"/> | ||
<TextBox Grid.Row="2" Name="AgentIdTextBox" Margin="10" Width="200"/> | ||
|
||
<Label Grid.Row="3" Content="Station Number:" Margin="10"/> | ||
<TextBox Grid.Row="3" Name="StationNumberTextBox" Margin="10" Width="200"/> | ||
|
||
<Label Grid.Row="4" Content="Active in Mission:" Margin="10"/> | ||
<CheckBox Grid.Row="4" Name="ActiveInMissionCheckBox" Margin="300,10,10,10" Background="Red" Checked="ActiveInMissionCheckBox_Checked" Unchecked="ActiveInMissionCheckBox_Unchecked"/> | ||
|
||
<Button Grid.Row="5" Name="SaveButton" Content="Save" Margin="10" Width="100" Click="SaveButton_Click"/> | ||
</Grid> | ||
</Page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data.SqlClient; | ||
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.Navigation; | ||
using System.Windows.Shapes; | ||
|
||
namespace IoT1.View | ||
{ | ||
/// <summary> | ||
/// Interaction logic for AddUserPage.xaml | ||
/// </summary> | ||
public partial class AddUserPage : Page | ||
{ | ||
public AddUserPage() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
private void SaveButton_Click(object sender, RoutedEventArgs e) | ||
{ | ||
string firstName = FirstNameTextBox.Text; | ||
string lastName = LastNameTextBox.Text; | ||
int agentId = int.Parse(AgentIdTextBox.Text); | ||
int stationNumber = int.Parse(StationNumberTextBox.Text); | ||
bool isActiveInMission = ActiveInMissionCheckBox.IsChecked ?? false; | ||
|
||
User newUser = new User | ||
{ | ||
FirstName = firstName, | ||
LastName = lastName, | ||
AgentId = agentId, | ||
StationNumber = stationNumber, | ||
IsActiveInMission = isActiveInMission | ||
}; | ||
|
||
using (SqlConnection connection = new SqlConnection(@"Data Source=(localdb)\Local; Database = LoginDB;Integrated Security = True;")) | ||
{ | ||
SqlCommand command = new SqlCommand("INSERT INTO Userspage (FirstName, LastName, AgentId, StationNumber, IsActive) " + | ||
"VALUES (@FirstName, @LastName, @AgentId, @StationNumber, @IsActiveInMission)", connection); | ||
command.Parameters.AddWithValue("@FirstName", newUser.FirstName); | ||
command.Parameters.AddWithValue("@LastName", newUser.LastName); | ||
command.Parameters.AddWithValue("@AgentId", newUser.AgentId); | ||
command.Parameters.AddWithValue("@StationNumber", newUser.StationNumber); | ||
command.Parameters.AddWithValue("@IsActiveInMission", newUser.IsActiveInMission); | ||
|
||
connection.Open(); | ||
int result = command.ExecuteNonQuery(); | ||
if (result == 1) | ||
{ | ||
MessageBox.Show("User added successfully!"); | ||
} | ||
} | ||
|
||
} | ||
private void ActiveInMissionCheckBox_Checked(object sender, RoutedEventArgs e) | ||
{ | ||
ActiveInMissionCheckBox.Background = Brushes.Green; | ||
} | ||
|
||
private void ActiveInMissionCheckBox_Unchecked(object sender, RoutedEventArgs e) | ||
{ | ||
ActiveInMissionCheckBox.Background = Brushes.Red; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,34 @@ | ||
<Window x:Class="IoT1.UserInputWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:iot1="clr-namespace:IoT1" | ||
Title="Add User" Height="250" Width="350"> | ||
Title="Add User" Height="450" Width="800"> | ||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="Auto"/> | ||
<RowDefinition Height="Auto"/> | ||
<RowDefinition Height="Auto"/> | ||
<RowDefinition Height="Auto"/> | ||
<RowDefinition Height="Auto"/> | ||
<RowDefinition Height="Auto"/> | ||
<RowDefinition Height="Auto"/> | ||
</Grid.RowDefinitions> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="Auto" /> | ||
<ColumnDefinition Width="*" /> | ||
</Grid.ColumnDefinitions> | ||
<Label Grid.Row="0" Grid.Column="0" Content="First Name:" /> | ||
<TextBox Grid.Row="0" Grid.Column="1" x:Name="txtFirstName" /> | ||
<Label Grid.Row="1" Grid.Column="0" Content="Last Name:" /> | ||
<TextBox Grid.Row="1" Grid.Column="1" x:Name="txtLastName" /> | ||
<Label Grid.Row="2" Grid.Column="0" Content="Agent ID:" /> | ||
<TextBox Grid.Row="2" Grid.Column="1" x:Name="txtAgentID" /> | ||
<Label Grid.Row="3" Grid.Column="0" Content="Station Number:" /> | ||
<TextBox Grid.Row="3" Grid.Column="1" x:Name="txtStationNumber" /> | ||
<Button Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" x:Name="btnSave" Content="Save" Click="BtnSave_Click" /> | ||
<Button Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" x:Name="btnCancel" Content="Cancel" Click="BtnCancel_Click" /> | ||
|
||
<Label Grid.Row="0" Content="First Name:" Margin="10"/> | ||
<TextBox Grid.Row="0" Name="FirstNameTextBox" Margin="10" Width="200"/> | ||
|
||
<Label Grid.Row="1" Content="Last Name:" Margin="10"/> | ||
<TextBox Grid.Row="1" Name="LastNameTextBox" Margin="10" Width="200"/> | ||
|
||
<Label Grid.Row="2" Content="Agent ID:" Margin="10"/> | ||
<TextBox Grid.Row="2" Name="AgentIdTextBox" Margin="10" Width="200"/> | ||
|
||
<Label Grid.Row="3" Content="Station Number:" Margin="10"/> | ||
<TextBox Grid.Row="3" Name="StationNumberTextBox" Margin="10" Width="200"/> | ||
|
||
<Label Grid.Row="4" Content="Active in Mission:" Margin="10"/> | ||
<CheckBox Grid.Row="4" Name="ActiveInMissionCheckBox" Margin="300,10,10,10" Background="Red" Checked="ActiveInMissionCheckBox_Checked" Unchecked="ActiveInMissionCheckBox_Unchecked"/> | ||
|
||
<Button Grid.Row="5" Name="SaveButton" Content="Save" Margin="10" Width="100" Click="SaveButton_Click"/> | ||
</Grid> | ||
|
||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.