From 1f6298551f262dcfcff876b1705daaf6bb0f6c26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Wed, 17 Feb 2021 19:28:46 +0100 Subject: [PATCH] Add project files. --- .gitattributes | 63 ++++ .gitignore | 340 +++++++++++++++++++ StockDal.Interface/IStockMarketRepository.cs | 20 ++ StockDal.Interface/IStockMemberRepository.cs | 16 + StockDal.Interface/StockDal.Interface.csproj | 16 + StockDal/AppConnection.cs | 15 + StockDal/StockDal.csproj | 19 ++ StockDal/StockMarketRepository.cs | 230 +++++++++++++ StockDal/StockMemberRepository.cs | 104 ++++++ StockDomain/DiTraderStockRow.cs | 22 ++ StockDomain/StockDomain.csproj | 7 + StockDomain/StockMember.cs | 25 ++ WpfStocks.sln | 43 +++ WpfStocks/App.xaml | 9 + WpfStocks/App.xaml.cs | 44 +++ WpfStocks/AssemblyInfo.cs | 10 + WpfStocks/Data/Employee.cs | 15 + WpfStocks/Data/EmployeeDbContext.cs | 44 +++ WpfStocks/Data/Product.cs | 17 + WpfStocks/MainWindow.xaml | 18 + WpfStocks/MainWindow.xaml.cs | 39 +++ WpfStocks/WpfStocks.csproj | 14 + 22 files changed, 1130 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 StockDal.Interface/IStockMarketRepository.cs create mode 100644 StockDal.Interface/IStockMemberRepository.cs create mode 100644 StockDal.Interface/StockDal.Interface.csproj create mode 100644 StockDal/AppConnection.cs create mode 100644 StockDal/StockDal.csproj create mode 100644 StockDal/StockMarketRepository.cs create mode 100644 StockDal/StockMemberRepository.cs create mode 100644 StockDomain/DiTraderStockRow.cs create mode 100644 StockDomain/StockDomain.csproj create mode 100644 StockDomain/StockMember.cs create mode 100644 WpfStocks.sln create mode 100644 WpfStocks/App.xaml create mode 100644 WpfStocks/App.xaml.cs create mode 100644 WpfStocks/AssemblyInfo.cs create mode 100644 WpfStocks/Data/Employee.cs create mode 100644 WpfStocks/Data/EmployeeDbContext.cs create mode 100644 WpfStocks/Data/Product.cs create mode 100644 WpfStocks/MainWindow.xaml create mode 100644 WpfStocks/MainWindow.xaml.cs create mode 100644 WpfStocks/WpfStocks.csproj diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4ce6fdd --- /dev/null +++ b/.gitignore @@ -0,0 +1,340 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- Backup*.rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb \ No newline at end of file diff --git a/StockDal.Interface/IStockMarketRepository.cs b/StockDal.Interface/IStockMarketRepository.cs new file mode 100644 index 0000000..48254f7 --- /dev/null +++ b/StockDal.Interface/IStockMarketRepository.cs @@ -0,0 +1,20 @@ +using StockDomain; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StockDal.Interface +{ + public interface IStockMarketRepository + { + Dictionary StockMarketList { get; set; } + bool ViewBrowser { get; set; } + + void Clean(); + void LoadStockMarketList(); + void LoadStockMarketList(bool viewBrowser); + void RefreshMarketList(); + } +} diff --git a/StockDal.Interface/IStockMemberRepository.cs b/StockDal.Interface/IStockMemberRepository.cs new file mode 100644 index 0000000..f9b0fb2 --- /dev/null +++ b/StockDal.Interface/IStockMemberRepository.cs @@ -0,0 +1,16 @@ +using StockDomain; +using System; +using System.Collections.Generic; + +namespace StockDal.Interface +{ + public interface IStockMemberRepository + { + IEnumerable GetStocks(); + //bool Insert(StockMember stockMember); + void UpdateActPrice(int Id, decimal price); + bool Delete(string stockMemberId); + void InsertMany(List stockMembers); + IEnumerable GetAllStocks(); + } +} diff --git a/StockDal.Interface/StockDal.Interface.csproj b/StockDal.Interface/StockDal.Interface.csproj new file mode 100644 index 0000000..55af59e --- /dev/null +++ b/StockDal.Interface/StockDal.Interface.csproj @@ -0,0 +1,16 @@ + + + + net5.0 + + + + + + + + + + + + diff --git a/StockDal/AppConnection.cs b/StockDal/AppConnection.cs new file mode 100644 index 0000000..df0833b --- /dev/null +++ b/StockDal/AppConnection.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RepositoryPattern +{ + + public class StockDBConnection + { + public static string ConnectionString => ConfigurationManager.ConnectionStrings["StockDB"].ConnectionString; + } +} diff --git a/StockDal/StockDal.csproj b/StockDal/StockDal.csproj new file mode 100644 index 0000000..f6a1392 --- /dev/null +++ b/StockDal/StockDal.csproj @@ -0,0 +1,19 @@ + + + + net5.0 + + + + + + + + + + + + + + + diff --git a/StockDal/StockMarketRepository.cs b/StockDal/StockMarketRepository.cs new file mode 100644 index 0000000..693759d --- /dev/null +++ b/StockDal/StockMarketRepository.cs @@ -0,0 +1,230 @@ +using Newtonsoft.Json; +using OpenQA.Selenium; +using OpenQA.Selenium.Chrome; +using StockDal.Interface; +using StockDomain; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StockDal +{ + public class StockMarketRepository : IStockMarketRepository + { + public Dictionary StockMarketList { get; set; } + + public List DumpObjects { get; set; } = new List(); + public DiTraderStockRow SaveRow { get; set; } + public StringBuilder TextResults { get; set; } + public bool ViewBrowser { get; set; } + + public IWebDriver driver; + + public StockMarketRepository() + { + ViewBrowser = false; + } + + private void Find_Data() + { + TextResults = new StringBuilder(); + IList searchElements = driver.FindElements(By.TagName("tbody")); + foreach (IWebElement i in searchElements) + { + + HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument(); + var text = i.GetAttribute("innerHTML"); + htmlDocument.LoadHtml(text); + var inputs = htmlDocument.DocumentNode.Descendants("tr").ToList(); + foreach (var items in inputs) + { + HtmlAgilityPack.HtmlDocument htmlDocument1 = new HtmlAgilityPack.HtmlDocument(); + htmlDocument1.LoadHtml(items.InnerHtml); + var tds = htmlDocument1.DocumentNode.Descendants("td").ToList(); + var appendText = ""; + var fNr = 0; + foreach (var item in tds) + { + var intext = item.InnerText.Replace("\r\n", ""); + appendText += appendText.Length == 0 ? intext : " " + intext; + if (tds.Count == 10) + { + AddValueToListRow(fNr++, intext); + } + } + if (!string.IsNullOrEmpty(appendText)) + { + TextResults.Append(appendText + "\r\n"); + } + htmlDocument1 = null; + } + htmlDocument = null; + + TextResults.Append("\r\n"); + } + + // var oxe = StockMarketList; + } + + private void SaveLogging() + { + var output = JsonConvert.SerializeObject(DumpObjects, Formatting.Indented); + File.WriteAllText($"D:\\TimCoDemos\\DemoLogs\\Log{DateTime.Now.ToShortDateString()}.txt",output); + } + + private void AddValueToListRow(int pos, string value) + { + switch (pos) + { + case 0: + { + SaveRow = new DiTraderStockRow(); + SaveRow.StockName = value; + break; + } + case 1: + { + SaveRow.ProcChange = string.IsNullOrWhiteSpace(value) ? 0 : decimal.Parse(value); + break; + } + case 2: + { + SaveRow.RealChange = string.IsNullOrWhiteSpace(value) ? 0 : decimal.Parse(value); + break; + } + case 3: + { + SaveRow.BuyPrice = string.IsNullOrWhiteSpace(value) ? 0 : decimal.Parse(value); + break; + } + case 4: + { + SaveRow.SellPrice = string.IsNullOrWhiteSpace(value) ? 0 : decimal.Parse(value); + break; + } + case 5: + { + SaveRow.LatestPrice = string.IsNullOrWhiteSpace(value) ? 0 : decimal.Parse(value); + break; + } + case 6: + { + SaveRow.HighestPrice = string.IsNullOrWhiteSpace(value) ? 0 : decimal.Parse(value); + break; + } + case 7: + { + SaveRow.LowestPrice = string.IsNullOrWhiteSpace(value) ? 0 : decimal.Parse(value); + break; + } + case 8: + { + + SaveRow.Volume = string.IsNullOrWhiteSpace(value) ? 0 : long.Parse(value.Replace(" ", "")); + break; + } + case 9: + { + SaveRow.TimeOfDay = value==""?TimeSpan.Parse("00:01"): TimeSpan.Parse(value); + //StockMarketList.Add(SaveRow.StockName, SaveRow); + try + { + StockMarketList.Add(SaveRow.StockName, SaveRow); + } + catch (ArgumentException ae) + { + try + { + StockMarketList.Add(SaveRow.StockName + "-2", SaveRow); + } + catch (Exception) + { + DumpObjects.Add(SaveRow); + } + + } + break; + } + default: + break; + } + } + + private void OpenBrowser(bool burl2 = false) + { + var driverService = ChromeDriverService.CreateDefaultService(); + driverService.HideCommandPromptWindow = true; + + if (ViewBrowser) + { + if (driver == null) + { + driver = new ChromeDriver(driverService); + } + } + else + { + if (driver == null) + { + var options = new ChromeOptions(); + options.AddArgument("headless"); + driver = new ChromeDriver(driverService, options); + } + } + + try + { + //var url0 = "https://money.cnn.com/data/hotstocks/index.html"; + var url = "https://trader.di.se/index.php/stocklist/index/2055?list=7126"; + var url2 = "https://trader.di.se/index.php/stocklist/index/2055?list=7116"; + //var url1 = "https://www.finansportalen.se/aktiekurser/"; + driver.Navigate().GoToUrl(burl2 ? url2 : url); + + } + catch + { + throw; + } + + } + + public void LoadStockMarketList() + { + StockMarketList = new Dictionary(); + DumpObjects = new List(); + OpenBrowser(); + Find_Data(); + OpenBrowser(true); + Find_Data(); + if (DumpObjects.Any()) + { + SaveLogging(); + } + } + + + public void LoadStockMarketList(bool viewBrowser) + { + StockMarketList = new Dictionary(); + ViewBrowser = viewBrowser; + OpenBrowser(); + Find_Data(); + } + + public void RefreshMarketList() + { + StockMarketList = new Dictionary(); + driver.Navigate().Refresh(); + Find_Data(); + } + + public void Clean() + { + driver?.Quit(); + } + + } +} diff --git a/StockDal/StockMemberRepository.cs b/StockDal/StockMemberRepository.cs new file mode 100644 index 0000000..9c75787 --- /dev/null +++ b/StockDal/StockMemberRepository.cs @@ -0,0 +1,104 @@ +using Dapper; +using RepositoryPattern; +using StockDal.Interface; +using StockDomain; +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.SqlClient; + +namespace StockDal +{ + public class StockMemberRepository : IStockMemberRepository + { + public bool Delete(string stockMemberId) + { + throw new NotImplementedException(); + } + + public void InsertMany(List stockMembers) + { + using IDbConnection db = new SqlConnection(StockDBConnection.ConnectionString); + if (db.State == ConnectionState.Closed) + db.Open(); + db.Execute( + @"INSERT INTO [dbo].[StockMember] + (StockId + ,StockExtId + ,BuyValue + ,BuyDate + ,ActValue + ,ActDate + ,SoldValue + ,SoldDate + ,Comment + ,PostAmount) + VALUES + (@StockId + ,@StockExtId + ,@BuyValue + ,@BuyDate + ,@ActValue + ,@ActDate + ,@SoldValue + ,@SoldDate + ,@Comment + ,@PostAmount) + ", stockMembers); + } + + public void UpdateActPrice(int Id, decimal price) + { + using IDbConnection db = new SqlConnection(StockDBConnection.ConnectionString); + if (db.State == ConnectionState.Closed) + db.Open(); + + db.Execute( + @"UPDATE [dbo].[StockMember] + SET ActValue = @val, + ActDate = @date + WHERE Id = @id + ", new { val = price, date = DateTime.Today, id = Id }); + } + + public IEnumerable GetStocks() + { + using IDbConnection db = new SqlConnection(StockDBConnection.ConnectionString); + if (db.State == ConnectionState.Closed) + db.Open(); + return db.Query(@"SELECT Id + ,StockId + ,StockExtId + ,BuyValue + ,BuyDate + ,ActValue + ,ActDate + ,SoldValue + ,SoldDate + ,Comment + ,PostAmount + FROM dbo.StockMember + Where SoldDate is null + ORDER BY PostAmount * (actvalue - BuyValue) desc", commandType: CommandType.Text); + } + public IEnumerable GetAllStocks() + { + using IDbConnection db = new SqlConnection(StockDBConnection.ConnectionString); + if (db.State == ConnectionState.Closed) + db.Open(); + return db.Query(@"SELECT Id + ,StockId + ,StockExtId + ,BuyValue + ,BuyDate + ,ActValue + ,ActDate + ,SoldValue + ,SoldDate + ,Comment + ,PostAmount + FROM dbo.StockMember + ORDER BY PostAmount * (actvalue - BuyValue) desc", commandType: CommandType.Text); + } + } +} diff --git a/StockDomain/DiTraderStockRow.cs b/StockDomain/DiTraderStockRow.cs new file mode 100644 index 0000000..47fda61 --- /dev/null +++ b/StockDomain/DiTraderStockRow.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StockDomain +{ + public class DiTraderStockRow + { + public string StockName { get; set; } + public decimal ProcChange { get; set; } + public decimal RealChange { get; set; } + public decimal BuyPrice { get; set; } + public decimal SellPrice { get; set; } + public decimal LatestPrice { get; set; } + public decimal HighestPrice { get; set; } + public decimal LowestPrice { get; set; } + public long Volume { get; set; } + public TimeSpan TimeOfDay { get; set; } + } +} diff --git a/StockDomain/StockDomain.csproj b/StockDomain/StockDomain.csproj new file mode 100644 index 0000000..f208d30 --- /dev/null +++ b/StockDomain/StockDomain.csproj @@ -0,0 +1,7 @@ + + + + net5.0 + + + diff --git a/StockDomain/StockMember.cs b/StockDomain/StockMember.cs new file mode 100644 index 0000000..6c45d9d --- /dev/null +++ b/StockDomain/StockMember.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; + + +namespace StockDomain +{ + public class StockMember + { + public int Id { get; set; } + public string StockId { get; set; } + public string StockExtId { get; set; } + public decimal BuyValue { get; set; } + public DateTime BuyDate { get; set; } + public decimal ActValue { get; set; } + public DateTime ActDate { get; set; } + public long ActAmount { get; set; } + public decimal SoldValue { get; set; } + public DateTime? SoldDate { get; set; } +// public string PostId { get; set; } + public string Comment { get; set; } + public long PostAmount { get; set; } + + } +} diff --git a/WpfStocks.sln b/WpfStocks.sln new file mode 100644 index 0000000..f97355e --- /dev/null +++ b/WpfStocks.sln @@ -0,0 +1,43 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30804.86 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StockDomain", "StockDomain\StockDomain.csproj", "{25899D94-D35E-44A1-BDD7-BDD5589DB2E0}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StockDal.Interface", "StockDal.Interface\StockDal.Interface.csproj", "{65F33E97-16CF-471A-9C59-D0D17287856C}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StockDal", "StockDal\StockDal.csproj", "{E3C410EE-5040-48E1-9C87-DC9A0D011DC7}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WpfStocks", "WpfStocks\WpfStocks.csproj", "{7640245C-91FF-4530-B909-32D347EC7FEA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {25899D94-D35E-44A1-BDD7-BDD5589DB2E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {25899D94-D35E-44A1-BDD7-BDD5589DB2E0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {25899D94-D35E-44A1-BDD7-BDD5589DB2E0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {25899D94-D35E-44A1-BDD7-BDD5589DB2E0}.Release|Any CPU.Build.0 = Release|Any CPU + {65F33E97-16CF-471A-9C59-D0D17287856C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {65F33E97-16CF-471A-9C59-D0D17287856C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {65F33E97-16CF-471A-9C59-D0D17287856C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {65F33E97-16CF-471A-9C59-D0D17287856C}.Release|Any CPU.Build.0 = Release|Any CPU + {E3C410EE-5040-48E1-9C87-DC9A0D011DC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E3C410EE-5040-48E1-9C87-DC9A0D011DC7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E3C410EE-5040-48E1-9C87-DC9A0D011DC7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E3C410EE-5040-48E1-9C87-DC9A0D011DC7}.Release|Any CPU.Build.0 = Release|Any CPU + {7640245C-91FF-4530-B909-32D347EC7FEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7640245C-91FF-4530-B909-32D347EC7FEA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7640245C-91FF-4530-B909-32D347EC7FEA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7640245C-91FF-4530-B909-32D347EC7FEA}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {DEA63362-5E0F-44C4-AF18-358A682FA93B} + EndGlobalSection +EndGlobal diff --git a/WpfStocks/App.xaml b/WpfStocks/App.xaml new file mode 100644 index 0000000..82f8479 --- /dev/null +++ b/WpfStocks/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/WpfStocks/App.xaml.cs b/WpfStocks/App.xaml.cs new file mode 100644 index 0000000..98e719e --- /dev/null +++ b/WpfStocks/App.xaml.cs @@ -0,0 +1,44 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; +using WpfStocks.Data; + +namespace WpfStocks +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + private ServiceProvider serviceProvider; + + public App() + { + ServiceCollection services = new ServiceCollection(); + ConfigureServices(services); + serviceProvider = services.BuildServiceProvider(); + } + + private void ConfigureServices(ServiceCollection services) + { + services.AddDbContext(options => + { + options.UseSqlite("Data Source = Employee.db"); + }); + + services.AddSingleton(); + } + + private void OnStartup(object sender , StartupEventArgs e) + { + var mainWindow = serviceProvider.GetService(); + mainWindow.Show(); + } + } +} diff --git a/WpfStocks/AssemblyInfo.cs b/WpfStocks/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/WpfStocks/AssemblyInfo.cs @@ -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) +)] diff --git a/WpfStocks/Data/Employee.cs b/WpfStocks/Data/Employee.cs new file mode 100644 index 0000000..6dc7e5d --- /dev/null +++ b/WpfStocks/Data/Employee.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WpfStocks.Data +{ + public class Employee + { + public int Id { get; set; } + public string FirstName { get; set; } + public string LastName { get; set; } + } +} diff --git a/WpfStocks/Data/EmployeeDbContext.cs b/WpfStocks/Data/EmployeeDbContext.cs new file mode 100644 index 0000000..1202376 --- /dev/null +++ b/WpfStocks/Data/EmployeeDbContext.cs @@ -0,0 +1,44 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WpfStocks.Data +{ + public class EmployeeDbContext : DbContext + { + #region Constructor + public EmployeeDbContext(DbContextOptions options) : base(options) + { + Database.EnsureCreated(); + } + #endregion + + #region Public Properties + public DbSet Employee { get; set; } + #endregion + + #region Overridden Method + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().HasData(GetEmployees()); + base.OnModelCreating(modelBuilder); + } + #endregion + + #region Private Method + private List GetEmployees() + { + return new List + { + new Employee {Id=100, FirstName="John",LastName="Doe"}, + new Employee {Id=101, FirstName="Nicole",LastName="Martha"}, + new Employee {Id=102, FirstName="Steve",LastName="Johnsson"}, + new Employee {Id=103, FirstName="Thomas",LastName="Bond"}, + }; + } + #endregion + } +} diff --git a/WpfStocks/Data/Product.cs b/WpfStocks/Data/Product.cs new file mode 100644 index 0000000..45f0573 --- /dev/null +++ b/WpfStocks/Data/Product.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WpfStocks.Data +{ + public class Product + { + public int Id { get; set; } + public string Name { get; set; } + public string Description { get; set; } + public double Price { get; set; } + public int Unit { get; set; } + } +} diff --git a/WpfStocks/MainWindow.xaml b/WpfStocks/MainWindow.xaml new file mode 100644 index 0000000..3f2df95 --- /dev/null +++ b/WpfStocks/MainWindow.xaml @@ -0,0 +1,18 @@ + + + + + + + + + + + diff --git a/WpfStocks/MainWindow.xaml.cs b/WpfStocks/MainWindow.xaml.cs new file mode 100644 index 0000000..a719062 --- /dev/null +++ b/WpfStocks/MainWindow.xaml.cs @@ -0,0 +1,39 @@ +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 WpfStocks.Data; + +namespace WpfStocks +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + EmployeeDbContext _dbContext; + + public MainWindow(EmployeeDbContext dbContext) + { + InitializeComponent(); + _dbContext = dbContext; + GetEmployees(); + } + + private void GetEmployees() + { + var employees = _dbContext.Employee.ToList(); + EmployeeDG.ItemsSource = employees; + } + } +} diff --git a/WpfStocks/WpfStocks.csproj b/WpfStocks/WpfStocks.csproj new file mode 100644 index 0000000..bfb3806 --- /dev/null +++ b/WpfStocks/WpfStocks.csproj @@ -0,0 +1,14 @@ + + + + WinExe + netcoreapp3.1 + true + + + + + + + +