add new project

main
syneffort 2 years ago
parent b36ad8fd09
commit 937fbc4bc0
  1. 22
      MySolution/DBCreateEF/Context/AppDbContext.cs
  2. 24
      MySolution/DBCreateEF/DBCreateEF.csproj
  3. 15
      MySolution/DBCreateEF/Model/Snack.cs
  4. 17
      MySolution/DBCreateEF/Program.cs
  5. 2
      MySolution/InventoryManagement_MariaDB/Program.cs
  6. 12
      MySolution/MySolution.sln
  7. 9
      MySolution/ToDoApp/App.xaml
  8. 17
      MySolution/ToDoApp/App.xaml.cs
  9. 10
      MySolution/ToDoApp/AssemblyInfo.cs
  10. 24
      MySolution/ToDoApp/Context/ToDoContext.cs
  11. 111
      MySolution/ToDoApp/Controller/ToDoController.cs
  12. 12
      MySolution/ToDoApp/MainWindow.xaml
  13. 51
      MySolution/ToDoApp/MainWindow.xaml.cs
  14. 30
      MySolution/ToDoApp/Model/Item.cs
  15. 33
      MySolution/ToDoApp/Model/User.cs
  16. 23
      MySolution/ToDoApp/ToDoApp.csproj
  17. 27
      MySolution/ToDoApp/Utility/Utils.cs

@ -0,0 +1,22 @@
using DBCreateEF.Model;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DBCreateEF.Context
{
internal class AppDbContext : DbContext
{
public DbSet<Snack> Snacks { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
//optionsBuilder.UseSqlServer(@"Data Source=peacecloud.synology.me,21433;Initial Catalog=Study;User ID=study;Password=Study1234;Encrypt=false");
optionsBuilder.UseMySQL(@"Server=peacecloud.synology.me;Port=3307;Database=Study;Uid=study;Pwd=Study1234!;");
base.OnConfiguring(optionsBuilder);
}
}
}

@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.13">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.13">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MySql.EntityFrameworkCore" Version="7.0.5" />
</ItemGroup>
</Project>

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DBCreateEF.Model
{
internal class Snack
{
public int Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
}
}

@ -0,0 +1,17 @@
using DBCreateEF.Context;
using Microsoft.EntityFrameworkCore;
namespace DBCreateEF
{
internal class Program
{
static void Main(string[] args)
{
using (var context = new AppDbContext())
{
context.Database.EnsureCreated();
//context.Database.Migrate();
}
}
}
}

@ -1,4 +1,5 @@
using InventoryManagement.Components; using InventoryManagement.Components;
using Microsoft.EntityFrameworkCore;
namespace InventoryManagement namespace InventoryManagement
{ {
@ -9,6 +10,7 @@ namespace InventoryManagement
using (var context = new InventoryContext()) using (var context = new InventoryContext())
{ {
context.Database.EnsureCreated(); context.Database.EnsureCreated();
//context.Database.Migrate();
} }
var InventoryManager = new InventoryManager(); var InventoryManager = new InventoryManager();

@ -23,6 +23,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EF_ChangeLog", "EF_ChangeLo
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InventoryManagement_MariaDB", "InventoryManagement_MariaDB\InventoryManagement_MariaDB.csproj", "{EF6B4197-EAF3-4F13-AA42-F25110F82D3E}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InventoryManagement_MariaDB", "InventoryManagement_MariaDB\InventoryManagement_MariaDB.csproj", "{EF6B4197-EAF3-4F13-AA42-F25110F82D3E}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DBCreateEF", "DBCreateEF\DBCreateEF.csproj", "{A3960078-A866-414F-B039-FCD4065E8F74}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ToDoApp", "ToDoApp\ToDoApp.csproj", "{D500F21E-3B7B-47DA-9D0C-69EB8A8FA3B1}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -69,6 +73,14 @@ Global
{EF6B4197-EAF3-4F13-AA42-F25110F82D3E}.Debug|Any CPU.Build.0 = Debug|Any CPU {EF6B4197-EAF3-4F13-AA42-F25110F82D3E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EF6B4197-EAF3-4F13-AA42-F25110F82D3E}.Release|Any CPU.ActiveCfg = Release|Any CPU {EF6B4197-EAF3-4F13-AA42-F25110F82D3E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EF6B4197-EAF3-4F13-AA42-F25110F82D3E}.Release|Any CPU.Build.0 = Release|Any CPU {EF6B4197-EAF3-4F13-AA42-F25110F82D3E}.Release|Any CPU.Build.0 = Release|Any CPU
{A3960078-A866-414F-B039-FCD4065E8F74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A3960078-A866-414F-B039-FCD4065E8F74}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A3960078-A866-414F-B039-FCD4065E8F74}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A3960078-A866-414F-B039-FCD4065E8F74}.Release|Any CPU.Build.0 = Release|Any CPU
{D500F21E-3B7B-47DA-9D0C-69EB8A8FA3B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D500F21E-3B7B-47DA-9D0C-69EB8A8FA3B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D500F21E-3B7B-47DA-9D0C-69EB8A8FA3B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D500F21E-3B7B-47DA-9D0C-69EB8A8FA3B1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

@ -0,0 +1,9 @@
<Application x:Class="ToDoApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ToDoApp"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace ToDoApp
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

@ -0,0 +1,10 @@
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

@ -0,0 +1,24 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ToDoApp.Model;
namespace ToDoApp.Context
{
public class ToDoContext : DbContext
{
public DbSet<User> Users { get; set; }
public DbSet<Item> Items { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseMySQL(@"Server=peacecloud.synology.me;Port=3307;Database=Study;Uid=study;Pwd=Study1234!;");
base.OnConfiguring(optionsBuilder);
}
}
}

@ -0,0 +1,111 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ToDoApp.Context;
using ToDoApp.Model;
using ToDoApp.Utility;
namespace ToDoApp.Controller
{
public class ToDoController
{
public static ToDoController Instance { get; set; } = new ToDoController();
public void EnsureCreated()
{
using (var context = new ToDoContext())
{
context.Database.EnsureCreated();
}
}
public User? FindUser(int id)
{
using (var context = new ToDoContext())
{
return context.Users.Find(id);
}
}
public User? FindUser(string username)
{
using (var context = new ToDoContext())
{
return context.Users.FirstOrDefault(u => u.Name == username);
}
}
public bool LoginCheckUser(string username, string password)
{
User? user = FindUser(username);
if (user == null)
return false;
return Utils.VerifyPassword(password, user.Password);
}
public void CreateUser(User user)
{
using (var context = new ToDoContext())
{
user.CreateDate = DateTime.Now;
context.Users.Add(user);
context.SaveChanges();
}
}
public void DisableUser(int id)
{
using (var context = new ToDoContext())
{
User? user = context.Users.Find(id);
if (user == null)
return;
user.Status = UserStatus.Invalid;
context.SaveChanges();
}
}
public void DisableUser(string username)
{
using (var context = new ToDoContext())
{
User? user = context.Users.FirstOrDefault(u => u.Name == username);
if (user == null)
return;
user.Status = UserStatus.Invalid;
context.SaveChanges();
}
}
public void RemoveUser(int id)
{
using (var context = new ToDoContext())
{
User? user = context.Users.Find(id);
if (user == null)
return;
context.Users.Remove(user);
context.SaveChanges();
}
}
public void RemoveUser(string username)
{
using (var context = new ToDoContext())
{
User? user = context.Users.FirstOrDefault(u => u.Name == username);
if (user == null)
return;
context.Users.Remove(user);
context.SaveChanges();
}
}
}
}

@ -0,0 +1,12 @@
<Window x:Class="ToDoApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ToDoApp"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
</Grid>
</Window>

@ -0,0 +1,51 @@
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;
using ToDoApp.Context;
using ToDoApp.Controller;
using ToDoApp.Model;
namespace ToDoApp
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
if (!CheckDB())
{
MessageBox.Show("데이터베이스가 정상적이지 않아 프로그램을 종료합니다.");
Application.Current.Shutdown();
}
}
private bool CheckDB()
{
try
{
ToDoController.Instance.EnsureCreated();
return true;
}
catch (Exception ex)
{
return false;
}
}
}
}

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ToDoApp.Model
{
public class Item
{
public int Id { get; set; }
[Required]
public int UserId { get; set; }
[Required]
public string Title { get; set; }
public string Description { get; set; }
public DateTime DueDate { get; set; }
public bool IsCompleted { get; set; }
public DateTime CreateDate { get; set; }
public User User { get; set; }
}
}

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ToDoApp.Model
{
public enum UserStatus
{
Valid,
Invalid
}
public class User
{
public int Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
public string Password { get; set; }
[EmailAddress(ErrorMessage = "Invalid email format")]
public string Email { get; set; }
public DateTime CreateDate { get; set; }
public UserStatus Status { get; set; }
}
}

@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.13">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.13">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MySql.EntityFrameworkCore" Version="7.0.5" />
</ItemGroup>
</Project>

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace ToDoApp.Utility
{
public class Utils
{
public static string HashPassword(string password)
{
using (var sha256 = SHA256.Create())
{
var hashedBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(password));
return BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
}
}
public static bool VerifyPassword(string inputPassword, string hashedPassword)
{
var hashedInput = HashPassword(inputPassword);
return hashedInput.Equals(hashedPassword);
}
}
}
Loading…
Cancel
Save