Skip to content

Commit 8496652

Browse files
committed
Save project in github
1 parent 8c7d997 commit 8496652

File tree

69 files changed

+8427
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+8427
-0
lines changed

Lesson07.sln

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.8.34511.84
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson07", "Lesson07\Lesson07.csproj", "{0299EA85-26DE-4977-83A7-4C4B3F26100F}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{0299EA85-26DE-4977-83A7-4C4B3F26100F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{0299EA85-26DE-4977-83A7-4C4B3F26100F}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{0299EA85-26DE-4977-83A7-4C4B3F26100F}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{0299EA85-26DE-4977-83A7-4C4B3F26100F}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {2703517F-80DA-4BFC-9907-D15C8279D1CE}
24+
EndGlobalSection
25+
EndGlobal

Lesson07/App.xaml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Application
2+
x:Class="Lesson07.App"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="clr-namespace:Lesson07"
6+
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
7+
StartupUri="MainWindow.xaml">
8+
<Application.Resources>
9+
<ResourceDictionary>
10+
<ResourceDictionary.MergedDictionaries>
11+
<materialDesign:BundledTheme
12+
BaseTheme="Light"
13+
PrimaryColor="DeepPurple"
14+
SecondaryColor="Lime" />
15+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
16+
</ResourceDictionary.MergedDictionaries>
17+
</ResourceDictionary>
18+
</Application.Resources>
19+
</Application>

Lesson07/App.xaml.cs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Configuration;
2+
using System.Data;
3+
using System.Windows;
4+
5+
namespace Lesson07
6+
{
7+
/// <summary>
8+
/// Interaction logic for App.xaml
9+
/// </summary>
10+
public partial class App : Application
11+
{
12+
}
13+
14+
}

Lesson07/AssemblyInfo.cs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Windows;
2+
3+
[assembly: ThemeInfo(
4+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
5+
//(used if a resource is not found in the page,
6+
// or application resource dictionaries)
7+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
8+
//(used if a resource is not found in the page,
9+
// app, or any theme specific resource dictionaries)
10+
)]

Lesson07/Data/InventoryDbContext.cs

+260
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
using Lesson07.Models;
2+
using Microsoft.EntityFrameworkCore;
3+
using System.Windows.Controls;
4+
5+
namespace Lesson07.Data
6+
{
7+
public class InventoryDbContext : DbContext
8+
{
9+
public virtual DbSet<Category> Categories { get; set; }
10+
public virtual DbSet<Product> Products { get; set; }
11+
public virtual DbSet<Supplier> Suppliers { get; set; }
12+
public virtual DbSet<Supply> Supplies { get; set; }
13+
public virtual DbSet<SupplyProduct> SupplyProducts { get; set; }
14+
public virtual DbSet<Customer> Customers { get; set; }
15+
public virtual DbSet<Sale> Sales { get; set; }
16+
public virtual DbSet<SaleProduct> SalesProducts { get; set; }
17+
18+
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
19+
{
20+
optionsBuilder.UseSqlServer("Data Source=WIN-37KMC9AKIMF;Initial Catalog=InventoryManagement;Integrated Security=True;Encrypt=False");
21+
22+
base.OnConfiguring(optionsBuilder);
23+
}
24+
25+
protected override void OnModelCreating(ModelBuilder modelBuilder)
26+
{
27+
#region Category
28+
29+
modelBuilder.Entity<Category>()
30+
.ToTable(nameof(Category));
31+
modelBuilder.Entity<Category>()
32+
.HasKey(x => x.Id);
33+
modelBuilder.Entity<Category>()
34+
.Property(x => x.Name)
35+
.HasMaxLength(150)
36+
.IsRequired();
37+
modelBuilder.Entity<Category>()
38+
.HasMany(c => c.Products)
39+
.WithOne(p => p.Category)
40+
.HasForeignKey(p => p.CategoryId);
41+
42+
#endregion
43+
44+
#region Product
45+
46+
modelBuilder.Entity<Product>()
47+
.ToTable(nameof(Product));
48+
modelBuilder.Entity<Product>()
49+
.HasKey(x => x.Id);
50+
modelBuilder.Entity<Product>()
51+
.Property(x => x.Name)
52+
.HasMaxLength(250)
53+
.IsRequired();
54+
modelBuilder.Entity<Product>()
55+
.Property(x => x.Description)
56+
.HasMaxLength(500)
57+
.IsRequired(false);
58+
modelBuilder.Entity<Product>()
59+
.Property(x => x.Price)
60+
.HasColumnType("money")
61+
.HasDefaultValue(0)
62+
.HasPrecision(18, 2);
63+
modelBuilder.Entity<Product>()
64+
.Property(x => x.ExpireDate)
65+
.IsRequired();
66+
67+
modelBuilder.Entity<Product>()
68+
.HasOne(p => p.Category)
69+
.WithMany(c => c.Products)
70+
.HasForeignKey(p => p.CategoryId);
71+
modelBuilder.Entity<Product>()
72+
.HasMany(p => p.SupplyProducts)
73+
.WithOne(sp => sp.Product)
74+
.HasForeignKey(sp => sp.ProductId);
75+
modelBuilder.Entity<Product>()
76+
.HasMany(sp => sp.SaleProducts)
77+
.WithOne(p => p.Product);
78+
79+
#endregion
80+
81+
#region Supplier
82+
83+
modelBuilder.Entity<Supplier>()
84+
.ToTable(nameof(Supplier));
85+
modelBuilder.Entity<Supplier>()
86+
.HasKey(x => x.Id);
87+
modelBuilder.Entity<Supplier>()
88+
.Property(x => x.FirstName)
89+
.HasMaxLength(150)
90+
.IsRequired();
91+
modelBuilder.Entity<Supplier>()
92+
.Property(x => x.LastName)
93+
.HasMaxLength(150)
94+
.IsRequired(false);
95+
modelBuilder.Entity<Supplier>()
96+
.Property(x => x.Company)
97+
.HasMaxLength(255)
98+
.IsRequired();
99+
modelBuilder.Entity<Supplier>()
100+
.Property(x => x.PhoneNumber)
101+
.HasMaxLength(13)
102+
.IsRequired();
103+
104+
#endregion
105+
106+
#region Supply
107+
108+
modelBuilder.Entity<Supply>()
109+
.ToTable(nameof(Supply));
110+
modelBuilder.Entity<Supply>()
111+
.HasKey(x => x.Id);
112+
modelBuilder.Entity<Supply>()
113+
.Property(x => x.Date)
114+
.IsRequired();
115+
modelBuilder.Entity<Supply>()
116+
.Property(x => x.TotalDue)
117+
.HasColumnType("money")
118+
.HasPrecision(18, 2);
119+
modelBuilder.Entity<Supply>()
120+
.Property(x => x.TotalPaid)
121+
.HasColumnType("money")
122+
.HasPrecision(18, 2);
123+
124+
modelBuilder.Entity<Supply>()
125+
.HasMany(x => x.SupplyProducts)
126+
.WithOne(sp => sp.Supply)
127+
.HasForeignKey(sp => sp.SupplyId);
128+
129+
#endregion
130+
131+
#region Supply Product
132+
133+
modelBuilder.Entity<SupplyProduct>()
134+
.ToTable(nameof(SupplyProduct));
135+
modelBuilder.Entity<SupplyProduct>()
136+
.HasKey(x => x.Id);
137+
modelBuilder.Entity<SupplyProduct>()
138+
.Property(x => x.Quantity)
139+
.IsRequired()
140+
.HasDefaultValue(1);
141+
modelBuilder.Entity<SupplyProduct>()
142+
.Property(x => x.UnitPrice)
143+
.HasColumnType("money")
144+
.HasPrecision(18, 2)
145+
.IsRequired();
146+
147+
modelBuilder.Entity<SupplyProduct>()
148+
.HasOne(sp => sp.Supply)
149+
.WithMany(s => s.SupplyProducts)
150+
.HasForeignKey(sp => sp.SupplyId);
151+
modelBuilder.Entity<SupplyProduct>()
152+
.HasOne(sp => sp.Product)
153+
.WithMany(p => p.SupplyProducts)
154+
.HasForeignKey(sp => sp.ProductId);
155+
156+
#endregion
157+
158+
#region Customer
159+
160+
modelBuilder.Entity<Customer>()
161+
.ToTable(nameof(Customer));
162+
modelBuilder.Entity<Customer>()
163+
.HasKey(x => x.Id);
164+
modelBuilder.Entity<Customer>()
165+
.Property(x => x.FirstName)
166+
.HasMaxLength(50)
167+
.IsRequired();
168+
modelBuilder.Entity<Customer>()
169+
.Property(x => x.LastName)
170+
.HasMaxLength(150)
171+
.IsRequired();
172+
modelBuilder.Entity<Customer>()
173+
.Property(x => x.PhoneNumber)
174+
.HasMaxLength(13)
175+
.IsRequired();
176+
modelBuilder.Entity<Customer>()
177+
.Property(x => x.Address)
178+
.HasMaxLength(100)
179+
.IsRequired(false);
180+
181+
modelBuilder.Entity<Customer>()
182+
.HasMany(c => c.Sales)
183+
.WithOne(s => s.Customer)
184+
.HasForeignKey(s => s.CustomerId);
185+
186+
187+
#endregion
188+
189+
#region Sale
190+
191+
modelBuilder.Entity <Sale>()
192+
.ToTable(nameof(Sale));
193+
modelBuilder.Entity<Sale>()
194+
.HasKey(x => x.Id);
195+
modelBuilder.Entity<Sale>()
196+
.Property(x => x.SaleDate)
197+
.IsRequired();
198+
modelBuilder.Entity<Sale>()
199+
.Property(x => x.TotalDue)
200+
.HasColumnType("money")
201+
.HasPrecision(18, 2)
202+
.IsRequired();
203+
modelBuilder.Entity<Sale>()
204+
.Property(x => x.TotalPaid)
205+
.HasColumnType("money")
206+
.HasPrecision(18, 2)
207+
.IsRequired();
208+
modelBuilder.Entity<Sale>()
209+
.Property(x => x.TotalDiscount)
210+
.HasPrecision(18, 2)
211+
.HasDefaultValue(0)
212+
.IsRequired();
213+
214+
modelBuilder.Entity<Sale>()
215+
.HasOne(s => s.Customer)
216+
.WithMany(c => c.Sales)
217+
.HasForeignKey(s => s.CustomerId);
218+
modelBuilder.Entity<Sale>()
219+
.HasMany(s => s.SaleProducts)
220+
.WithOne(sp => sp.Sale)
221+
.HasForeignKey(sp => sp.SaleId);
222+
223+
#endregion
224+
225+
#region SaleProduct
226+
227+
modelBuilder.Entity<SaleProduct>()
228+
.ToTable(nameof(SaleProduct));
229+
modelBuilder.Entity<SaleProduct>()
230+
.HasKey(x => x.Id);
231+
232+
modelBuilder.Entity<SaleProduct>()
233+
.Property(x => x.Quantity)
234+
.HasDefaultValue(1);
235+
modelBuilder.Entity<SaleProduct>()
236+
.Property(x => x.UnitPrice)
237+
.HasColumnType("money")
238+
.HasPrecision(18, 2)
239+
.IsRequired();
240+
modelBuilder.Entity<SaleProduct>()
241+
.Property(x => x.Discount)
242+
.HasPrecision(18, 2)
243+
.HasColumnType("money")
244+
.IsRequired();
245+
246+
modelBuilder.Entity<SaleProduct>()
247+
.HasOne(sp => sp.Sale)
248+
.WithMany(s => s.SaleProducts)
249+
.HasForeignKey(sp => sp.SaleId);
250+
modelBuilder.Entity<SaleProduct>()
251+
.HasOne(sp => sp.Product)
252+
.WithMany(p => p.SaleProducts)
253+
.HasForeignKey(sp => sp.ProductId);
254+
255+
#endregion
256+
257+
base.OnModelCreating(modelBuilder);
258+
}
259+
}
260+
}

0 commit comments

Comments
 (0)