Skip to content

Commit

Permalink
Login, Registration and Location pages added.(TODO Location page)
Browse files Browse the repository at this point in the history
  • Loading branch information
SKrishna791 committed Mar 15, 2023
1 parent 0f8eb0d commit a399229
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 12 deletions.
14 changes: 14 additions & 0 deletions IoT1/IoT1.csproj
Expand Up @@ -118,6 +118,12 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Location.xaml.cs">
<DependentUpon>Location.xaml</DependentUpon>
</Compile>
<Compile Include="RegisterPage.xaml.cs">
<DependentUpon>RegisterPage.xaml</DependentUpon>
</Compile>
<Compile Include="User.cs" />
<Compile Include="UserInputWindow.xaml.cs">
<DependentUpon>UserInputWindow.xaml</DependentUpon>
Expand All @@ -133,6 +139,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Location.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="LoginPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand All @@ -158,6 +168,10 @@
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="RegisterPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UserInputWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
14 changes: 14 additions & 0 deletions IoT1/Location.xaml
@@ -0,0 +1,14 @@
<Page x:Class="IoT1.Location"
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"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="Location">

<Grid>

</Grid>
</Page>
28 changes: 28 additions & 0 deletions IoT1/Location.xaml.cs
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
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
{
/// <summary>
/// Interaction logic for Location.xaml
/// </summary>
public partial class Location : Page
{
public Location()
{
InitializeComponent();
}
}
}
30 changes: 18 additions & 12 deletions IoT1/LoginPage.xaml
Expand Up @@ -7,21 +7,27 @@
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="LoginPage"
Background="Transparent">
Background="Beige">

<Grid>
<Grid.ColumnDefinitions>
<StackPanel Margin="20">

<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<TextBlock Text="Hello there" FontSize="20" Background="SlateGray"/>
<Label Content="Login" Foreground="Black" HorizontalAlignment="Center" FontSize="24"
FontWeight="Bold"/>
<Image Source="Images/firefighter1.png" Height="53" Width="375"/>


<Label Content="Username" FontSize="20" FontWeight="Bold" HorizontalAlignment="Center"/>
<TextBox x:Name="txtUsername" Background="White" Width="592" Height="31" FontSize="18"/>

<Label Content="Password" FontSize="20" FontWeight="Bold" HorizontalAlignment="Center"/>
<PasswordBox x:Name="txtPassword" Background="White" Width="585" Height="31" FontSize="18"/>

<Button x:Name="btnSubmit" Click="btnSubmit_Click" Content="Login" Margin="60 " Background="#FFB9B9DE" Width="219" BorderBrush="{x:Null}" FontWeight="Bold" FontSize="15"/>
<Button Content="Register" Click="Button_Click" Background="#FF9A9AEC" Width="125" BorderBrush="#FFDCAFAF" FontWeight="Bold" Height="33" FontSize="20" Margin="-30" />


</StackPanel>

</Grid>
</Page>
54 changes: 54 additions & 0 deletions IoT1/LoginPage.xaml.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -24,5 +25,58 @@ public LoginPage()
{
InitializeComponent();
}

private void btnSubmit_Click(object sender, RoutedEventArgs e)
{

// For Windows auth -
// @"Data Source=(MachineName)\InstanceName);Initial Catalog = (DBName); Integrated Security = True;"
// For SQL Server auth -
// @"Data Source=(MachineName)\InstanceName);Initial Catalog = (DBName); UserID = Username; Password = (Password);"
SqlConnection sqlCon = new SqlConnection(@"Data Source=(localdb)\Local; Database = LoginDB;Integrated Security = True;");

try
{
if (sqlCon.State == System.Data.ConnectionState.Closed)
sqlCon.Open();
String query = "SELECT COUNT(1) FROM tblUser WHERE Username = @Username AND Password =@Password";
SqlCommand sqlCmd = new SqlCommand(query, sqlCon);
sqlCmd.CommandType = System.Data.CommandType.Text;

sqlCmd.Parameters.AddWithValue("@Username", txtUsername.Text);
sqlCmd.Parameters.AddWithValue("@Password", txtPassword.Password);
int count = Convert.ToInt32(sqlCmd.ExecuteScalar());

if (count == 1)
{
MainWindow dashboard = new MainWindow();
dashboard.Show();
MessageBox.Show("Login Successful");
this.NavigationService.Navigate(null);
}

else
{
MessageBox.Show("Invalid Username/Password");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);

}

finally
{
sqlCon.Close();
}
}

private void Button_Click(object sender, RoutedEventArgs e)
{
RegisterPage registerPage = new RegisterPage();
this.NavigationService.Navigate(registerPage);

}
}
}
31 changes: 31 additions & 0 deletions IoT1/RegisterPage.xaml
@@ -0,0 +1,31 @@
<Page x:Class="IoT1.RegisterPage"
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"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="RegisterPage" Background="AliceBlue">

<StackPanel Margin="20">



<Label Content="Register" Foreground="Black" HorizontalAlignment="Center" FontSize="24"
FontWeight="Bold"/>



<Label Content="Username" FontSize="20" FontWeight="Bold" HorizontalAlignment="Center"/>
<TextBox x:Name="txt_Username" Background="White" Width="592" Height="31" FontSize="18"/>

<Label Content="Password" FontSize="20" FontWeight="Bold" HorizontalAlignment="Center"/>
<PasswordBox x:Name="txt_Password" Background="White" Width="585" Height="31" FontSize="18"/>


<Button Content="Register" Width="213" Margin="30" Click="Button_Click"/>

</StackPanel>

</Page>
55 changes: 55 additions & 0 deletions IoT1/RegisterPage.xaml.cs
@@ -0,0 +1,55 @@
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
{
/// <summary>
/// Interaction logic for RegisterPage.xaml
/// </summary>
public partial class RegisterPage : Page
{
public RegisterPage()
{
InitializeComponent();
}

SqlConnection conn = new SqlConnection(@"Data Source=(localdb)\Local;Initial Catalog=LoginDB;Integrated Security=True");

private void Button_Click(object sender, RoutedEventArgs e)
{
try
{
SqlCommand cmd = new SqlCommand("INSERT INTO tblUser VALUES (@Username, @Password)", conn);
cmd.CommandType = System.Data.CommandType.Text;
cmd.Parameters.AddWithValue("@Username", txt_Username.Text);
cmd.Parameters.AddWithValue("@Password", txt_Password.Password);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("Registration Completed ");

}

catch (SqlException Ex)
{

MessageBox.Show(Ex.Message);

}

}
}
}

0 comments on commit a399229

Please sign in to comment.