Skip to content

Commit 6f4c9fd

Browse files
author
Amal Raj Umapathy Selvam
committed
Demo has been added
1 parent 94b7b46 commit 6f4c9fd

27 files changed

Lines changed: 1157 additions & 0 deletions
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Window
3+
x:Class="SQLiteWithWinUIDataGrid.AddOrEditWindow"
4+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6+
xmlns:local="using:SQLiteWithWinUIDataGrid"
7+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
mc:Ignorable="d">
10+
11+
<Grid Margin="5" x:Name="AddEditGrid">
12+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
13+
<Grid >
14+
<Grid.ColumnDefinitions>
15+
<ColumnDefinition Width="150"/>
16+
<ColumnDefinition Width="250"/>
17+
</Grid.ColumnDefinitions>
18+
<Grid.RowDefinitions>
19+
<RowDefinition />
20+
<RowDefinition />
21+
<RowDefinition />
22+
<RowDefinition />
23+
<RowDefinition />
24+
<RowDefinition />
25+
<RowDefinition />
26+
</Grid.RowDefinitions>
27+
28+
<TextBlock Grid.Column="0" Grid.Row="0" Text="Employee ID:" HorizontalAlignment="Right" VerticalAlignment="Center" />
29+
<NumberBox Grid.Column="1" Grid.Row="0" x:Name="employeeIDTextBox" Text="{Binding EmployeeID}" Margin="5" />
30+
31+
<TextBlock Grid.Column="0" Grid.Row="1" Text="Employee Name:" HorizontalAlignment="Right" VerticalAlignment="Center" />
32+
<TextBox Grid.Column="1" Grid.Row="1" x:Name="employeeNameTextBox" Text="{Binding Name}" Margin="5" />
33+
34+
<TextBlock Grid.Column="0" Grid.Row="2" Text="Employee Mail:" HorizontalAlignment="Right" VerticalAlignment="Center" />
35+
<TextBox Grid.Column="1" Grid.Row="2" x:Name="EmployeeMailTextBox" Text="{Binding EMail}" Margin="5"/>
36+
37+
<TextBlock Grid.Column="0" Grid.Row="3" Text="Employee Birth Date:" HorizontalAlignment="Right" VerticalAlignment="Center" />
38+
<CalendarDatePicker Grid.Column="1" Grid.Row="3" x:Name="EmployeeBirthDatePicker" Date="{Binding BirthDate}" Margin="5" />
39+
40+
<TextBlock Grid.Column="0" Grid.Row="4" Text="Employee Gender:" HorizontalAlignment="Right" VerticalAlignment="Center" />
41+
<ComboBox Grid.Column="1" Grid.Row="4" x:Name="GenderComboBox" SelectedItem="{Binding Gender}" Margin="5">
42+
<x:String>Male</x:String>
43+
<x:String>Female</x:String>
44+
</ComboBox>
45+
<TextBlock Grid.Column="0" Grid.Row="5" Text="Employee Location:" HorizontalAlignment="Right" VerticalAlignment="Center" />
46+
<TextBox Grid.Column="1" Grid.Row="5" x:Name="EmployeeLocationTextBox" Text="{Binding Location}" Margin="5"/>
47+
<StackPanel Grid.Column="1" Grid.Row="6" Orientation="Horizontal">
48+
<Button Content="Save" Click="OnSaveClick" Margin="2" />
49+
<Button Content="Cancel" Click="OnCancelClick" Margin="2"/>
50+
</StackPanel>
51+
</Grid>
52+
</StackPanel>
53+
</Grid>
54+
</Window>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Runtime.InteropServices.WindowsRuntime;
6+
using Windows.Foundation;
7+
using Windows.Foundation.Collections;
8+
using Microsoft.UI.Xaml;
9+
using Microsoft.UI.Xaml.Controls;
10+
using Microsoft.UI.Xaml.Controls.Primitives;
11+
using Microsoft.UI.Xaml.Data;
12+
using Microsoft.UI.Xaml.Input;
13+
using Microsoft.UI.Xaml.Media;
14+
using Microsoft.UI.Xaml.Navigation;
15+
16+
// To learn more about WinUI, the WinUI project structure,
17+
// and more about our project templates, see: http://aka.ms/winui-project-info.
18+
19+
namespace SQLiteWithWinUIDataGrid
20+
{
21+
/// <summary>
22+
/// An empty window that can be used on its own or navigated to within a Frame.
23+
/// </summary>
24+
public sealed partial class AddOrEditWindow : Window
25+
{
26+
public AddOrEditWindow()
27+
{
28+
this.InitializeComponent();
29+
this.Activated += OnActivated;
30+
}
31+
32+
private void OnActivated(object sender, WindowActivatedEventArgs args)
33+
{
34+
this.AddEditGrid.DataContext = this.SelectedRecord;
35+
}
36+
37+
public Employee SelectedRecord { get; set; }
38+
39+
private async void OnSaveClick(object sender, RoutedEventArgs e)
40+
{
41+
bool isEdit = true;
42+
if (SelectedRecord == null)
43+
{
44+
isEdit = false;
45+
SelectedRecord = new Employee();
46+
}
47+
48+
SelectedRecord.EmployeeID = this.employeeIDTextBox.Value;
49+
SelectedRecord.Name = this.employeeNameTextBox.Text;
50+
SelectedRecord.EMail = this.EmployeeMailTextBox.Text;
51+
SelectedRecord.Gender = this.GenderComboBox.SelectedItem.ToString();
52+
SelectedRecord.BirthDate = this.EmployeeBirthDatePicker.Date;
53+
SelectedRecord.Location = this.EmployeeLocationTextBox.Text;
54+
55+
if (isEdit)
56+
await App.Database.UpdateEmployeeAsync(SelectedRecord);
57+
else
58+
await App.Database.AddEmployeeAsync(SelectedRecord);
59+
60+
this.Close();
61+
}
62+
63+
private void OnCancelClick(object sender, RoutedEventArgs e)
64+
{
65+
this.Close();
66+
}
67+
}
68+
}

SQLiteWithWinUIDataGrid/App.xaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Application
3+
x:Class="SQLiteWithWinUIDataGrid.App"
4+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6+
xmlns:local="using:SQLiteWithWinUIDataGrid">
7+
<Application.Resources>
8+
<ResourceDictionary>
9+
<ResourceDictionary.MergedDictionaries>
10+
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
11+
<!-- Other merged dictionaries here -->
12+
</ResourceDictionary.MergedDictionaries>
13+
<!-- Other app resources here -->
14+
</ResourceDictionary>
15+
</Application.Resources>
16+
</Application>
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
using Microsoft.UI.Windowing;
2+
using Microsoft.UI.Xaml;
3+
using Microsoft.UI.Xaml.Controls;
4+
using Microsoft.UI.Xaml.Controls.Primitives;
5+
using Microsoft.UI.Xaml.Data;
6+
using Microsoft.UI.Xaml.Input;
7+
using Microsoft.UI.Xaml.Media;
8+
using Microsoft.UI.Xaml.Navigation;
9+
using Microsoft.UI.Xaml.Shapes;
10+
using SQLiteWithWinUIDataGrid.DataBase;
11+
using System;
12+
using System.Collections.Generic;
13+
using System.IO;
14+
using System.Linq;
15+
using System.Runtime.InteropServices.WindowsRuntime;
16+
using Windows.ApplicationModel;
17+
using Windows.ApplicationModel.Activation;
18+
using Windows.Foundation;
19+
using Windows.Foundation.Collections;
20+
21+
// To learn more about WinUI, the WinUI project structure,
22+
// and more about our project templates, see: http://aka.ms/winui-project-info.
23+
24+
namespace SQLiteWithWinUIDataGrid
25+
{
26+
/// <summary>
27+
/// Provides application-specific behavior to supplement the default Application class.
28+
/// </summary>
29+
public partial class App : Application
30+
{
31+
/// <summary>
32+
/// Initializes the singleton application object. This is the first line of authored code
33+
/// executed, and as such is the logical equivalent of main() or WinMain().
34+
/// </summary>
35+
public App()
36+
{
37+
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("MDAxQDMyMzQyZTMwMmUzMEdudGcxQ1EvZkF6TW1xcXJlM3p2dC92cjZQaEtqbklYSDQvbUdTdTRndGs9");
38+
this.InitializeComponent();
39+
}
40+
41+
static SQLiteDatabase database;
42+
43+
// Create the database connection as a singleton.
44+
public static SQLiteDatabase Database
45+
{
46+
get
47+
{
48+
if (database == null)
49+
{
50+
database = new SQLiteDatabase();
51+
}
52+
return database;
53+
}
54+
}
55+
56+
public static Window MainWindow
57+
{
58+
get
59+
{
60+
return m_window;
61+
}
62+
}
63+
64+
/// <summary>
65+
/// Invoked when the application is launched.
66+
/// </summary>
67+
/// <param name="args">Details about the launch request and process.</param>
68+
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
69+
{
70+
m_window = new MainWindow();
71+
ShowWindowAtCenter(m_window.AppWindow, m_window.AppWindow.ClientSize.Height, m_window.AppWindow.ClientSize.Width);
72+
m_window.Activate();
73+
}
74+
75+
public static void ShowWindowAtCenter(AppWindow appWindow, int height, int width)
76+
{
77+
var a = DisplayArea.Primary;
78+
if (a != null)
79+
{
80+
var outerBounds = a.WorkArea;
81+
82+
var midtY = outerBounds.Height / 2;
83+
var startY = midtY - (height / 2);
84+
85+
if (startY < 0)
86+
startY = 0;
87+
88+
var midtX = outerBounds.Width / 2;
89+
var startX = midtX - (width / 2);
90+
91+
if (startX < 0)
92+
startX = 0;
93+
94+
appWindow.MoveAndResize(new Windows.Graphics.RectInt32((int)startX, (int)startY, width, height));
95+
}
96+
}
97+
98+
private static Window m_window;
99+
}
100+
}
432 Bytes
Loading
5.25 KB
Loading
1.71 KB
Loading
637 Bytes
Loading
283 Bytes
Loading
456 Bytes
Loading

0 commit comments

Comments
 (0)