Skip to content

Commit 52bb2fd

Browse files
Merge pull request #3 from ShawnLaMountain/main
Added WinForms sample 'SimpleContacts'
2 parents acfd1ff + 10e2989 commit 52bb2fd

File tree

14 files changed

+743
-0
lines changed

14 files changed

+743
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ Grab the latest [ThunderDesign.Net-PCL.SQLite NuGet](https://www.nuget.org/packa
3131
3232
Use the `-version` option to specify an [older version](https://www.nuget.org/packages/ThunderDesign.Net-PCL.SQLite#versions-tab) to install.
3333

34+
## Examples
35+
36+
*(TIP: Clone repo, open the solution, build it and run sample app.)*
37+
- WinForms
38+
- [SimpleContacts Examples](https://github.com/ThunderDesign/ThunderDesign.Net-PCL.SQLite/tree/main/samples/WinForms/SimpleContacts)
39+
3440
## Please Contribute!
3541

3642
This is an open source project that welcomes contributions/suggestions/bug reports from those who use it. If you have any ideas on how to improve the library, please [post an issue here on GitHub](https://github.com/ThunderDesign/ThunderDesign.Net-PCL.SQLite/issues). Please check out the [How to Contribute](https://github.com/ThunderDesign/ThunderDesign.Net-PCL.SQLite/blob/main/.github/CONTRIBUTING.md).
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.1.32127.271
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleContacts", "SimpleContacts\SimpleContacts.csproj", "{AA88F337-DD27-4C88-8BE5-E1E4F7AFD60D}"
7+
EndProject
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ThunderDesign.Net-PCL.SQLite", "..\..\..\src\ThunderDesign.Net-PCL.SQLite\ThunderDesign.Net-PCL.SQLite.csproj", "{00E7FCCF-4240-4E13-9FC1-DD2A60EF8155}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{AA88F337-DD27-4C88-8BE5-E1E4F7AFD60D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{AA88F337-DD27-4C88-8BE5-E1E4F7AFD60D}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{AA88F337-DD27-4C88-8BE5-E1E4F7AFD60D}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{AA88F337-DD27-4C88-8BE5-E1E4F7AFD60D}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{00E7FCCF-4240-4E13-9FC1-DD2A60EF8155}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{00E7FCCF-4240-4E13-9FC1-DD2A60EF8155}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{00E7FCCF-4240-4E13-9FC1-DD2A60EF8155}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{00E7FCCF-4240-4E13-9FC1-DD2A60EF8155}.Release|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {A04264C0-1ABF-4A93-A391-9E3B4F18983A}
30+
EndGlobalSection
31+
EndGlobal
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using SimpleContacts.Database.Tables;
2+
using SimpleContacts.Databases.ORMs;
3+
using ThunderDesign.Net.SQLite.Bridges;
4+
5+
namespace SimpleContacts.Database.Bridges
6+
{
7+
public class ContactsBridge : BaseBridge<ushort, ContactsORM>
8+
{
9+
#region constructors
10+
public ContactsBridge() : base(ContactsTable.Instance)
11+
{
12+
}
13+
#endregion
14+
15+
#region properties
16+
public static ContactsBridge Instance
17+
{
18+
get
19+
{
20+
lock (_Locker)
21+
{
22+
return _Instance ??= new ContactsBridge();
23+
}
24+
}
25+
}
26+
#endregion
27+
28+
#region variables
29+
protected readonly static object _Locker = new();
30+
private static ContactsBridge? _Instance = null;
31+
#endregion
32+
}
33+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using ThunderDesign.Net.SQLite.Connections;
2+
3+
namespace SimpleContacts.Databases.Connections
4+
{
5+
public class SimpleContactsConnection : BaseSQLiteConnection
6+
{
7+
#region constructors
8+
public SimpleContactsConnection() : base(_DatabaseFilename)
9+
{
10+
}
11+
#endregion
12+
13+
#region properties
14+
public static SimpleContactsConnection Instance
15+
{
16+
get
17+
{
18+
lock (_Locker)
19+
{
20+
return _Instance ??= new SimpleContactsConnection();
21+
}
22+
}
23+
}
24+
#endregion
25+
26+
#region variables
27+
private const string _DatabaseFilename = "Contacts.db3";
28+
private static SimpleContactsConnection? _Instance = null;
29+
#endregion
30+
}
31+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using SQLite;
2+
using ThunderDesign.Net.SQLite.ORMs;
3+
using ThunderDesign.Net.Threading.Extentions;
4+
5+
namespace SimpleContacts.Databases.ORMs
6+
{
7+
[Table("Contacts")]
8+
public class ContactsORM : BaseSQLiteORM_AutoIncrement<ushort>
9+
{
10+
#region properties
11+
[Column("first_name")]
12+
public string FirstName
13+
{
14+
get { return this.GetProperty(ref _FirstName, _Locker); }
15+
set
16+
{
17+
if (this.SetProperty(ref _FirstName, value, _Locker, true))
18+
this.OnPropertyChanged(nameof(FullName));
19+
}
20+
}
21+
22+
[Column("last_name")]
23+
public string LastName
24+
{
25+
get { return this.GetProperty(ref _LastName, _Locker); }
26+
set
27+
{
28+
if (this.SetProperty(ref _LastName, value, _Locker, true))
29+
this.OnPropertyChanged(nameof(FullName));
30+
}
31+
}
32+
33+
[Ignore]
34+
public string FullName
35+
{
36+
get { return GetFullName(); }
37+
}
38+
#endregion
39+
40+
#region methods
41+
private string GetFullName()
42+
{
43+
return $"{LastName}, {FirstName} = {Id}";
44+
}
45+
#endregion
46+
47+
#region variables
48+
protected string _FirstName = String.Empty;
49+
protected string _LastName = String.Empty;
50+
#endregion
51+
52+
}
53+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using SimpleContacts.Databases.Connections;
2+
using SimpleContacts.Databases.ORMs;
3+
using ThunderDesign.Net.SQLite.Tables;
4+
5+
namespace SimpleContacts.Database.Tables
6+
{
7+
public class ContactsTable : BaseSQLiteTable<ContactsORM>
8+
{
9+
#region constructors
10+
public ContactsTable() : base(SimpleContactsConnection.Instance)
11+
{
12+
}
13+
#endregion
14+
15+
#region properties
16+
public static ContactsTable Instance
17+
{
18+
get
19+
{
20+
lock (_Locker)
21+
{
22+
return _Instance ??= new ContactsTable();
23+
}
24+
}
25+
}
26+
#endregion
27+
28+
#region variables
29+
private static ContactsTable? _Instance = null;
30+
#endregion
31+
32+
}
33+
}

samples/WinForms/SimpleContacts/SimpleContacts/FormContactInfo.Designer.cs

Lines changed: 123 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using SimpleContacts.Databases.ORMs;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.ComponentModel;
5+
using System.Data;
6+
using System.Drawing;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
using System.Windows.Forms;
11+
12+
namespace SimpleContacts
13+
{
14+
public partial class Form_ContactInfo : Form
15+
{
16+
#region constructors
17+
public Form_ContactInfo(ContactsORM contactsORM) : base()
18+
{
19+
InitializeComponent();
20+
_ContactsORM = contactsORM;
21+
TextBox_FirstName.Text = contactsORM.FirstName;
22+
TextBox_LastName.Text = contactsORM.LastName;
23+
}
24+
#endregion
25+
26+
#region methods
27+
private void Button_Save_Click(object sender, EventArgs e)
28+
{
29+
if (String.IsNullOrEmpty(TextBox_LastName.Text))
30+
{
31+
MessageBox.Show("Last Name is required");
32+
TextBox_LastName.Focus();
33+
return;
34+
}
35+
36+
if (String.IsNullOrEmpty(TextBox_FirstName.Text))
37+
{
38+
MessageBox.Show("First Name is required");
39+
TextBox_FirstName.Focus();
40+
return;
41+
}
42+
43+
_ContactsORM.FirstName = TextBox_FirstName.Text;
44+
_ContactsORM.LastName = TextBox_LastName.Text;
45+
46+
this.DialogResult = DialogResult.OK;
47+
}
48+
#endregion
49+
50+
#region variables
51+
private readonly ContactsORM _ContactsORM;
52+
#endregion
53+
}
54+
}

0 commit comments

Comments
 (0)