New projct BrowserDriver infered to help with webscraping

This commit is contained in:
2022-02-01 21:15:31 +01:00
parent 5e42d91c1e
commit 5f0c4ef990
17 changed files with 472 additions and 649 deletions

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Selenium.Support" Version="4.1.0" />
<PackageReference Include="Selenium.WebDriver" Version="4.1.0" />
<PackageReference Include="WebDriverManager" Version="2.12.3" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,33 @@
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using WebDriverManager;
using WebDriverManager.DriverConfigs.Impl;
namespace BrowserHelper.Driver;
public class BrowserDriver : IBrowserDriver
{
public IWebDriver GetChromeDriver(bool headless = true)
{
new DriverManager().SetUpDriver(new ChromeConfig());
ChromeOptions options = new ChromeOptions();
if (headless)
options.AddArguments("--headless");
return new ChromeDriver(options);
}
public IWebDriver GetFirefoxDriver(bool headless = true)
{
new DriverManager().SetUpDriver(new FirefoxConfig());
FirefoxOptions options = new FirefoxOptions();
if (headless)
options.AddArguments("--headless");
return new FirefoxDriver(options);
}
}
public enum BrowserType
{
Chrome,
Firefox
}

View File

@ -0,0 +1,40 @@
using BrowserHelper.Settings;
using OpenQA.Selenium;
using System;
namespace BrowserHelper.Driver
{
public class DriverFixture : IDriverFixture, IDisposable
{
IWebDriver driver;
private readonly TestSettings _testSettings;
private readonly IBrowserDriver _browserDriver;
public DriverFixture(TestSettings testSettings, IBrowserDriver browserDriver)
{
_testSettings = testSettings;
_browserDriver = browserDriver;
driver = GetWebDriver();
driver.Navigate().GoToUrl(_testSettings.ApplicationUrl);
}
public IWebDriver Driver => driver;
public IWebDriver GetWebDriver()
{
return _testSettings.BrowserType switch
{
BrowserType.Chrome => _browserDriver.GetChromeDriver(_testSettings.Headless),
BrowserType.Firefox => _browserDriver.GetFirefoxDriver(_testSettings.Headless),
_ => _browserDriver.GetChromeDriver()
};
}
public void Dispose()
{
driver.Quit();
}
}
}

View File

@ -0,0 +1,9 @@
using OpenQA.Selenium;
namespace BrowserHelper.Driver;
public interface IBrowserDriver
{
IWebDriver GetChromeDriver(bool headless = true);
IWebDriver GetFirefoxDriver(bool headless = true);
}

View File

@ -0,0 +1,10 @@
using OpenQA.Selenium;
namespace BrowserHelper.Driver
{
public interface IDriverFixture
{
IWebDriver Driver { get; }
}
}

View File

@ -0,0 +1,248 @@
using OpenQA.Selenium;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BrowserHelper.Extensions
{
public static class HtmlTableExtension
{
//Read of Table
private static List<TableDataCollection> ReadTable(IWebElement table)
{
var tableDataCollection = new List<TableDataCollection>();
var columns = table.FindElements(By.TagName("th"));
var rows = table.FindElements(By.TagName("tr"));
int rowIndex = 0;
foreach (var row in rows)
{
int colIndex = 0;
var colDatas = row.FindElements(By.TagName("td"));
if (colDatas.Count != 0)
foreach (var colValue in colDatas)
{
tableDataCollection.Add(new TableDataCollection
{
RowNumber = rowIndex,
ColumnName = columns[colIndex].Text != "" ?
columns[colIndex].Text : colIndex.ToString(),
ColumnValue = colValue.Text,
ColumnSpecialValue = GetControl(colValue)
});
colIndex++;
}
rowIndex++;
}
return tableDataCollection;
}
private static List<TableDataCollection> ReadTablePartly(IWebElement table, string[] shares, string[] shareHeaders)
{
var tableDataCollection = new List<TableDataCollection>();
var columns = table.FindElements(By.TagName("th"));
var rows = table.FindElements(By.TagName("tr"));
var antal = shares.Length;
int rowIndex = 0;
foreach (var row in rows)
{
int colIndex = 0;
var colDatas = row.FindElements(By.TagName("td"));
if (colDatas.Count != 0 && shares.Contains(colDatas[0].Text))
{
if (colDatas.Count != 0)
foreach (var colValue in colDatas)
{
if (shareHeaders.Contains(columns[colIndex].Text))
{
tableDataCollection.Add(new TableDataCollection
{
RowNumber = rowIndex,
ColumnName = columns[colIndex].Text != "" ?
columns[colIndex].Text : colIndex.ToString(),
ColumnValue = colValue.Text,
ColumnSpecialValue = GetControl(colValue)
});
}
colIndex++;
}
rowIndex++;
antal--;
}
if (antal < 1) break;
}
return tableDataCollection;
}
private static ColumnSpecialValue GetControl(IWebElement columnValue)
{
ColumnSpecialValue? columnSpecialValue = null;
if (columnValue.FindElements(By.TagName("a")).Count > 0)
{
columnSpecialValue = new ColumnSpecialValue
{
ElementCollection = columnValue.FindElements(By.TagName("a")),
ControlType = ControlType.hyperlink
};
}
if (columnValue.FindElements(By.TagName("input")).Count > 0)
{
columnSpecialValue = new ColumnSpecialValue
{
ElementCollection = columnValue.FindElements(By.TagName("input")),
ControlType = ControlType.input
};
}
return columnSpecialValue;
}
public static List<TableDataCollection> ReadHandledStock(this IWebElement table)
{
var tableDataCollection = new List<TableDataCollection>();
var columns = table.FindElements(By.TagName("th"));
var rows = table.FindElements(By.TagName("tr"));
var antal = rows.Count;
int rowIndex = 0;
foreach (var row in rows)
{
var colDatas = row.FindElements(By.TagName("td"));
if (colDatas.Count != 0)
{
if (colDatas.Count != 0)
tableDataCollection.Add(new TableDataCollection
{
RowNumber = rowIndex,
ColumnName = columns[0].Text,
ColumnValue = colDatas[0].Text,
ColumnSpecialValue = null
});
}
rowIndex++;
antal--;
if (antal < 0) break;
}
return tableDataCollection;
}
public static List<Share> GetCertainStocks(this IWebElement element, string[] shares, string[] shareHeaders)
{
List<Share> shareList = new List<Share>();
var reducedList = ReadTablePartly(element, shares, shareHeaders);
int rNr = -1;
Share Aktie = null;
foreach (var shareRow in reducedList)
{
if (shareRow.RowNumber != rNr)
{
if (Aktie != null)
{
shareList.Add(Aktie);
}
Aktie = new();
rNr = shareRow.RowNumber;
}
switch (shareRow.ColumnName)
{
case "Aktie":
{
Aktie.AktieNamn = shareRow.ColumnValue;
break;
}
case "Senast":
{
Aktie.SenastePris = Convert.ToDecimal(shareRow.ColumnValue);
break;
}
case "Tid":
{
Aktie.RegTime = TimeOnly.Parse(shareRow.ColumnValue);
break;
}
}
}
shareList.Add(Aktie);
return shareList;
}
public static void PerformActionOnCell(this IWebElement element, string targetColumnIndex, string refColumnName, string refColumnValue, string controlToOperate = null)
{
var table = ReadTable(element);
foreach (int rowNumber in GetDynamicRowNumber(table, refColumnName, refColumnValue))
{
var cell = (from e in table
where e.ColumnName == targetColumnIndex && e.RowNumber == rowNumber
select e.ColumnSpecialValue).SingleOrDefault();
if (controlToOperate != null && cell != null)
{
IWebElement elementToClick = null;
if (cell.ControlType == ControlType.hyperlink)
{
elementToClick = (from c in cell.ElementCollection
where c.Text == controlToOperate.ToString()
select c).SingleOrDefault();
}
if (cell.ControlType == ControlType.input)
{
elementToClick = (from c in cell.ElementCollection
where c.GetAttribute("value") == controlToOperate.ToString()
select c).SingleOrDefault();
}
elementToClick?.Click();
}
else
{
cell.ElementCollection?.First().Click();
}
}
}
private static IEnumerable GetDynamicRowNumber(List<TableDataCollection> tableCollection, string columnName, string columnValue)
{
foreach (var table in tableCollection)
{
if (table.ColumnName == columnName && table.ColumnValue == columnValue)
yield return table.RowNumber;
}
}
}
public class TableDataCollection
{
public int RowNumber { get; set; }
public string? ColumnName { get; set; }
public string? ColumnValue { get; set; }
public ColumnSpecialValue? ColumnSpecialValue { get; set; }
}
public class ColumnSpecialValue
{
public IEnumerable<IWebElement>? ElementCollection { get; set; }
public ControlType? ControlType { get; set; }
}
public enum ControlType
{
hyperlink,
input,
option,
select
}
public class Share
{
public string AktieNamn { get; set; }
public decimal SenastePris { get; set; }
public TimeOnly RegTime { get; set; }
}
}

View File

@ -0,0 +1,39 @@
using BrowserHelper.Driver;
using Microsoft.Extensions.DependencyInjection;
using System.IO;
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Serialization;
using BrowserHelper.Settings;
namespace BrowserHelper.Extensions;
public static class WebDriverInitializerExtension
{
public static IServiceCollection UseWebDriverInitializer(
this IServiceCollection services)
{
services.AddSingleton(ReadConfig());
return services;
}
private static TestSettings ReadConfig()
{
var configFile = File
.ReadAllText(Path.GetDirectoryName(
Assembly.GetExecutingAssembly().Location)
+ "/appsettings.json");
var jsonSerializeOptions = new JsonSerializerOptions()
{
PropertyNameCaseInsensitive = true
};
jsonSerializeOptions.Converters.Add(new JsonStringEnumConverter());
var testSettings = JsonSerializer.Deserialize<TestSettings>(configFile, jsonSerializeOptions);
return testSettings;
}
}

View File

@ -0,0 +1,35 @@
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
namespace BrowserHelper.Extensions
{
public static class WebElementExtension
{
public static void SelectDropDownByText(this IWebElement element, string text)
{
var select = new SelectElement(element);
select.SelectByText(text);
}
public static void SelectDropDownByValue(this IWebElement element, string value)
{
var select = new SelectElement(element);
select.SelectByValue(value);
}
public static void SelectDropDownByIndex(this IWebElement element, int index)
{
var select = new SelectElement(element);
select.SelectByIndex(index);
}
public static void ClearAndEnterText(this IWebElement element, string value)
{
element.Clear();
element.SendKeys(value);
}
public static string GetSelectedDropDownValue(this IWebElement element)
{
return new SelectElement(element).SelectedOption.Text;
}
}
}

View File

@ -0,0 +1,8 @@
namespace BrowserHelper
{
public interface IMessages
{
string SayGoodBye();
string SayHello();
}
}

14
BrowserHelper/Messages.cs Normal file
View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BrowserHelper
{
public class Messages : IMessages
{
public string SayHello() => "Hello Viewer";
public string SayGoodBye() => "GoddBye, farewell, and good day!";
}
}

View File

@ -0,0 +1,15 @@
using System;
using BrowserHelper.Driver;
namespace BrowserHelper.Settings
{
public class TestSettings
{
public BrowserType BrowserType { get; set; }
public bool Headless { get; set; }
public Uri ApplicationUrl { get; set; }
public int TimeoutInterval { get; set; }
public string[] StockWishes { get; set; }
public string[] StocWishCols { get; set; }
}
}

View File

@ -1,25 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\DataDomain\DataDomain.csproj" />
<ProjectReference Include="..\DatamodelLibrary\DatamodelLibrary.csproj" />
<ProjectReference Include="..\Helpers\Helpers.csproj" />
<ProjectReference Include="..\StockBL.Interface\StockBL.Interface.csproj" />
<ProjectReference Include="..\StockBL\StockBL.csproj" />
<ProjectReference Include="..\StockDal.Interface\StockDAL.Interface.csproj" />
<ProjectReference Include="..\StockDAL\StockDAL.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="frmEditStock.cs">
<SubType>Form</SubType>
</Compile>
</ItemGroup>
</Project>

View File

@ -1,23 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HandleNewWindows
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}

View File

@ -1,381 +0,0 @@

namespace StockInfoCore
{
partial class frmEditStock
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnClose = new System.Windows.Forms.Button();
this.lblStockExtId = new System.Windows.Forms.Label();
this.txtStockExtId = new System.Windows.Forms.TextBox();
this.txtBuyPrice = new System.Windows.Forms.TextBox();
this.lblBuyPrice = new System.Windows.Forms.Label();
this.txtBuyDate = new System.Windows.Forms.TextBox();
this.lblBuyDate = new System.Windows.Forms.Label();
this.txtBoughtAmount = new System.Windows.Forms.TextBox();
this.lblBoughtAmount = new System.Windows.Forms.Label();
this.txtActValue = new System.Windows.Forms.TextBox();
this.lblActValue = new System.Windows.Forms.Label();
this.txtActDate = new System.Windows.Forms.TextBox();
this.lblActDate = new System.Windows.Forms.Label();
this.txtActAmount = new System.Windows.Forms.TextBox();
this.lblRemaining = new System.Windows.Forms.Label();
this.txtSoldPrice = new System.Windows.Forms.TextBox();
this.lblSoldValue = new System.Windows.Forms.Label();
this.txtSoldDate = new System.Windows.Forms.TextBox();
this.lblSoldDate = new System.Windows.Forms.Label();
this.txtComment = new System.Windows.Forms.TextBox();
this.lblComment = new System.Windows.Forms.Label();
this.btnSaveToDB = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.txtLatestSoldDate = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.txtLatestSoldPrice = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.txtStockName = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// btnClose
//
this.btnClose.Location = new System.Drawing.Point(437, 414);
this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(75, 23);
this.btnClose.TabIndex = 1;
this.btnClose.Text = "Close";
this.btnClose.UseVisualStyleBackColor = true;
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// lblStockExtId
//
this.lblStockExtId.AutoSize = true;
this.lblStockExtId.Location = new System.Drawing.Point(38, 44);
this.lblStockExtId.Name = "lblStockExtId";
this.lblStockExtId.Size = new System.Drawing.Size(62, 15);
this.lblStockExtId.TabIndex = 2;
this.lblStockExtId.Text = "StockExtId";
//
// txtStockExtId
//
this.txtStockExtId.Location = new System.Drawing.Point(153, 41);
this.txtStockExtId.Name = "txtStockExtId";
this.txtStockExtId.Size = new System.Drawing.Size(269, 23);
this.txtStockExtId.TabIndex = 3;
//
// txtBuyPrice
//
this.txtBuyPrice.Location = new System.Drawing.Point(153, 104);
this.txtBuyPrice.Name = "txtBuyPrice";
this.txtBuyPrice.Size = new System.Drawing.Size(111, 23);
this.txtBuyPrice.TabIndex = 5;
//
// lblBuyPrice
//
this.lblBuyPrice.AutoSize = true;
this.lblBuyPrice.Location = new System.Drawing.Point(38, 107);
this.lblBuyPrice.Name = "lblBuyPrice";
this.lblBuyPrice.Size = new System.Drawing.Size(56, 15);
this.lblBuyPrice.TabIndex = 4;
this.lblBuyPrice.Text = "Buy price";
//
// txtBuyDate
//
this.txtBuyDate.Location = new System.Drawing.Point(153, 133);
this.txtBuyDate.Name = "txtBuyDate";
this.txtBuyDate.Size = new System.Drawing.Size(142, 23);
this.txtBuyDate.TabIndex = 7;
//
// lblBuyDate
//
this.lblBuyDate.AutoSize = true;
this.lblBuyDate.Location = new System.Drawing.Point(38, 136);
this.lblBuyDate.Name = "lblBuyDate";
this.lblBuyDate.Size = new System.Drawing.Size(73, 15);
this.lblBuyDate.TabIndex = 6;
this.lblBuyDate.Text = "Bought Date";
//
// txtBoughtAmount
//
this.txtBoughtAmount.Location = new System.Drawing.Point(153, 162);
this.txtBoughtAmount.Name = "txtBoughtAmount";
this.txtBoughtAmount.Size = new System.Drawing.Size(111, 23);
this.txtBoughtAmount.TabIndex = 9;
this.txtBoughtAmount.TextChanged += new System.EventHandler(this.txtBoughtAmount_TextChanged);
//
// lblBoughtAmount
//
this.lblBoughtAmount.AutoSize = true;
this.lblBoughtAmount.Location = new System.Drawing.Point(38, 165);
this.lblBoughtAmount.Name = "lblBoughtAmount";
this.lblBoughtAmount.Size = new System.Drawing.Size(93, 15);
this.lblBoughtAmount.TabIndex = 8;
this.lblBoughtAmount.Text = "Bought Number";
//
// txtActValue
//
this.txtActValue.Location = new System.Drawing.Point(153, 191);
this.txtActValue.Name = "txtActValue";
this.txtActValue.Size = new System.Drawing.Size(111, 23);
this.txtActValue.TabIndex = 11;
//
// lblActValue
//
this.lblActValue.AutoSize = true;
this.lblActValue.Location = new System.Drawing.Point(38, 194);
this.lblActValue.Name = "lblActValue";
this.lblActValue.Size = new System.Drawing.Size(76, 15);
this.lblActValue.TabIndex = 10;
this.lblActValue.Text = "Current price";
//
// txtActDate
//
this.txtActDate.Location = new System.Drawing.Point(153, 220);
this.txtActDate.Name = "txtActDate";
this.txtActDate.Size = new System.Drawing.Size(142, 23);
this.txtActDate.TabIndex = 13;
//
// lblActDate
//
this.lblActDate.AutoSize = true;
this.lblActDate.Location = new System.Drawing.Point(38, 223);
this.lblActDate.Name = "lblActDate";
this.lblActDate.Size = new System.Drawing.Size(61, 15);
this.lblActDate.TabIndex = 12;
this.lblActDate.Text = "Value date";
//
// txtActAmount
//
this.txtActAmount.Location = new System.Drawing.Point(153, 249);
this.txtActAmount.Name = "txtActAmount";
this.txtActAmount.Size = new System.Drawing.Size(111, 23);
this.txtActAmount.TabIndex = 15;
//
// lblRemaining
//
this.lblRemaining.AutoSize = true;
this.lblRemaining.Location = new System.Drawing.Point(38, 252);
this.lblRemaining.Name = "lblRemaining";
this.lblRemaining.Size = new System.Drawing.Size(109, 15);
this.lblRemaining.TabIndex = 14;
this.lblRemaining.Text = "Remaining number";
//
// txtSoldPrice
//
this.txtSoldPrice.Location = new System.Drawing.Point(153, 278);
this.txtSoldPrice.Name = "txtSoldPrice";
this.txtSoldPrice.Size = new System.Drawing.Size(111, 23);
this.txtSoldPrice.TabIndex = 17;
//
// lblSoldValue
//
this.lblSoldValue.AutoSize = true;
this.lblSoldValue.Location = new System.Drawing.Point(38, 281);
this.lblSoldValue.Name = "lblSoldValue";
this.lblSoldValue.Size = new System.Drawing.Size(59, 15);
this.lblSoldValue.TabIndex = 16;
this.lblSoldValue.Text = "Sold price";
//
// txtSoldDate
//
this.txtSoldDate.Location = new System.Drawing.Point(153, 307);
this.txtSoldDate.Name = "txtSoldDate";
this.txtSoldDate.Size = new System.Drawing.Size(142, 23);
this.txtSoldDate.TabIndex = 19;
//
// lblSoldDate
//
this.lblSoldDate.AutoSize = true;
this.lblSoldDate.Location = new System.Drawing.Point(38, 310);
this.lblSoldDate.Name = "lblSoldDate";
this.lblSoldDate.Size = new System.Drawing.Size(57, 15);
this.lblSoldDate.TabIndex = 18;
this.lblSoldDate.Text = "Sold Date";
//
// txtComment
//
this.txtComment.Location = new System.Drawing.Point(153, 336);
this.txtComment.Multiline = true;
this.txtComment.Name = "txtComment";
this.txtComment.Size = new System.Drawing.Size(269, 72);
this.txtComment.TabIndex = 21;
//
// lblComment
//
this.lblComment.AutoSize = true;
this.lblComment.Location = new System.Drawing.Point(39, 339);
this.lblComment.Name = "lblComment";
this.lblComment.Size = new System.Drawing.Size(61, 15);
this.lblComment.TabIndex = 20;
this.lblComment.Text = "Comment";
//
// btnSaveToDB
//
this.btnSaveToDB.Location = new System.Drawing.Point(347, 414);
this.btnSaveToDB.Name = "btnSaveToDB";
this.btnSaveToDB.Size = new System.Drawing.Size(75, 23);
this.btnSaveToDB.TabIndex = 25;
this.btnSaveToDB.Text = "Save";
this.btnSaveToDB.UseVisualStyleBackColor = true;
this.btnSaveToDB.Click += new System.EventHandler(this.btnSaveToDB_Click);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.txtLatestSoldDate);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.txtLatestSoldPrice);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Location = new System.Drawing.Point(301, 81);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(255, 83);
this.groupBox1.TabIndex = 26;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Latest Sold";
//
// txtLatestSoldDate
//
this.txtLatestSoldDate.Location = new System.Drawing.Point(127, 52);
this.txtLatestSoldDate.Name = "txtLatestSoldDate";
this.txtLatestSoldDate.ReadOnly = true;
this.txtLatestSoldDate.Size = new System.Drawing.Size(111, 23);
this.txtLatestSoldDate.TabIndex = 9;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 55);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(56, 15);
this.label2.TabIndex = 8;
this.label2.Text = "Sold date";
//
// txtLatestSoldPrice
//
this.txtLatestSoldPrice.Location = new System.Drawing.Point(127, 23);
this.txtLatestSoldPrice.Name = "txtLatestSoldPrice";
this.txtLatestSoldPrice.ReadOnly = true;
this.txtLatestSoldPrice.Size = new System.Drawing.Size(111, 23);
this.txtLatestSoldPrice.TabIndex = 7;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 26);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(59, 15);
this.label1.TabIndex = 6;
this.label1.Text = "Sold price";
//
// txtStockName
//
this.txtStockName.Location = new System.Drawing.Point(153, 12);
this.txtStockName.Name = "txtStockName";
this.txtStockName.Size = new System.Drawing.Size(269, 23);
this.txtStockName.TabIndex = 27;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(38, 15);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(46, 15);
this.label3.TabIndex = 28;
this.label3.Text = "StockId";
//
// frmEditStock
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(570, 452);
this.Controls.Add(this.label3);
this.Controls.Add(this.txtStockName);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.btnSaveToDB);
this.Controls.Add(this.txtComment);
this.Controls.Add(this.lblComment);
this.Controls.Add(this.txtSoldDate);
this.Controls.Add(this.lblSoldDate);
this.Controls.Add(this.txtSoldPrice);
this.Controls.Add(this.lblSoldValue);
this.Controls.Add(this.txtActAmount);
this.Controls.Add(this.lblRemaining);
this.Controls.Add(this.txtActDate);
this.Controls.Add(this.lblActDate);
this.Controls.Add(this.txtActValue);
this.Controls.Add(this.lblActValue);
this.Controls.Add(this.txtBoughtAmount);
this.Controls.Add(this.lblBoughtAmount);
this.Controls.Add(this.txtBuyDate);
this.Controls.Add(this.lblBuyDate);
this.Controls.Add(this.txtBuyPrice);
this.Controls.Add(this.lblBuyPrice);
this.Controls.Add(this.txtStockExtId);
this.Controls.Add(this.lblStockExtId);
this.Controls.Add(this.btnClose);
this.Name = "frmEditStock";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "frmRegisterStock";
this.Shown += new System.EventHandler(this.frmRegisterStock_Shown);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.Label lblStockExtId;
private System.Windows.Forms.TextBox txtStockExtId;
private System.Windows.Forms.TextBox txtBuyPrice;
private System.Windows.Forms.Label lblBuyPrice;
private System.Windows.Forms.TextBox txtBuyDate;
private System.Windows.Forms.Label lblBuyDate;
private System.Windows.Forms.TextBox txtBoughtAmount;
private System.Windows.Forms.Label lblBoughtAmount;
private System.Windows.Forms.TextBox txtActValue;
private System.Windows.Forms.Label lblActValue;
private System.Windows.Forms.TextBox txtActDate;
private System.Windows.Forms.Label lblActDate;
private System.Windows.Forms.TextBox txtActAmount;
private System.Windows.Forms.Label lblRemaining;
private System.Windows.Forms.TextBox txtSoldPrice;
private System.Windows.Forms.Label lblSoldValue;
private System.Windows.Forms.TextBox txtSoldDate;
private System.Windows.Forms.Label lblSoldDate;
private System.Windows.Forms.TextBox txtComment;
private System.Windows.Forms.Label lblComment;
private System.Windows.Forms.Button btnSaveToDB;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox txtLatestSoldDate;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox txtLatestSoldPrice;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtStockName;
private System.Windows.Forms.Label label3;
}
}

View File

@ -1,153 +0,0 @@
using DataDomain;
using StockDAL.Interface;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace StockInfoCore
{
public partial class frmEditStock : Form
{
Color hdr = Color.Red;
private readonly IStockRepository _stockRepository;
public int CurrentStockMember { get; set; }
//public Dictionary<string, DiTraderStockRow> Stocks { get; set; }
//public List<StockMember> RegisteredStocks { get; set; } = new List<StockMember>();
public frmEditStock(IStockRepository stockRepository)
{
InitializeComponent();
_stockRepository = stockRepository;
}
//private void LoadStockCombo()
//{
// if (Stocks.Count() > 0)
// {
// foreach (var key in Stocks.Keys)
// {
// cmbStockChoser.Items.Add(key);
// }
// }
//}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void frmRegisterStock_Shown(object sender, EventArgs e)
{
LoadStockData();
//LoadStockCombo();
}
private void LoadStockData()
{
var stockChosen = _stockRepository.GetStockMember(CurrentStockMember);
txtStockExtId.Text = stockChosen.StockExtId;
txtActValue.Text = stockChosen.ActValue.ToString();
//txtActDate.Text = (DateTime.Today + stockChosen.ActDate.Value.TimeOfDay).ToString();
var stockSold = _stockRepository.LatestSell(stockChosen.StockId.Trim());
if (stockSold != null)
{
if (stockSold.LatestSoldDate != null)
{
txtLatestSoldDate.Text = stockSold.LatestSoldDate.Value.ToString();
txtLatestSoldPrice.Text = stockSold.SoldStockPrice.ToString();
}
else
{
txtLatestSoldDate.Text = string.Empty;
txtLatestSoldPrice.Text = string.Empty;
}
}
else
{
txtLatestSoldDate.Text = string.Empty;
txtLatestSoldPrice.Text = string.Empty;
}
txtBuyPrice.Text = stockChosen.BuyValue.ToString(); // = decimal.Parse(string.IsNullOrEmpty(txtBuyPrice.Text) ? "0" : txtBuyPrice.Text);
txtBoughtAmount.Text = stockChosen.PostAmount.ToString(); // = long.Parse(string.IsNullOrEmpty(txtBoughtAmount.Text) ? "0" : txtBoughtAmount.Text);
txtActDate.Text = stockChosen.ActDate.ToString(); // = DateTime.Parse(txtActDate.Text);
txtBuyDate.Text = stockChosen.BuyDate.ToString(); // = string.IsNullOrWhiteSpace(txtBuyDate.Text) ? DateTime.Today : DateTime.Parse(txtBuyDate.Text);
txtActValue.Text = stockChosen.ActValue.ToString(); // = decimal.Parse(string.IsNullOrEmpty(txtActValue.Text) ? "0" : txtActValue.Text);
txtActAmount.Text = stockChosen.ActAmount.ToString(); // = long.Parse(string.IsNullOrEmpty(txtActAmount.Text) ? "0" : txtActAmount.Text);
txtSoldDate.Text = stockChosen.SoldDate.ToString(); // = null; //DateTime.MaxValue;
txtSoldPrice.Text = stockChosen.SoldValue.ToString(); // = decimal.Parse("0");
txtComment.Text = stockChosen.Comment;
}
private void AddValidateData()
{
var currentStock = new StockMember();
currentStock.StockId = txtStockName.Text.Trim();
currentStock.StockExtId = txtStockExtId.Text;
currentStock.BuyValue = decimal.Parse(string.IsNullOrEmpty(txtBuyPrice.Text) ? "0" : txtBuyPrice.Text);
currentStock.PostAmount = long.Parse(string.IsNullOrEmpty(txtBoughtAmount.Text) ? "0" : txtBoughtAmount.Text);
currentStock.ActDate = DateTime.Parse(txtActDate.Text);
currentStock.BuyDate = string.IsNullOrWhiteSpace(txtBuyDate.Text) ? DateTime.Today : DateTime.Parse(txtBuyDate.Text);
currentStock.ActValue = decimal.Parse(string.IsNullOrEmpty(txtActValue.Text) ? "0" : txtActValue.Text);
currentStock.ActAmount = long.Parse(string.IsNullOrEmpty(txtActAmount.Text) ? "0" : txtActAmount.Text);
currentStock.SoldDate = DateTime.Parse(txtSoldDate.Text);
currentStock.SoldValue = decimal.Parse(txtSoldPrice.Text);
currentStock.Comment = txtComment.Text;
//RegisteredStocks.Add(currentStock);
try
{
_stockRepository.SaveStockMember(currentStock);
initiateRegWin();
}
catch (Exception ex)
{
MessageBox.Show($"Problems with update :{ex.Message}");
}
}
private void initiateRegWin()
{
txtStockExtId.Text = "";
txtBuyPrice.Text = "";
txtBuyDate.Text = "";
txtBoughtAmount.Text = "";
txtActValue.Text = "";
txtActDate.Text = "";
txtActAmount.Text = "";
txtSoldPrice.Text = "";
txtSoldDate.Text = "";
txtComment.Text = "";
}
private void btnSaveToDB_Click(object sender, EventArgs e)
{
AddValidateData();
}
private void txtBoughtAmount_TextChanged(object sender, EventArgs e)
{
txtActAmount.Text = txtBoughtAmount.Text;
}
private void lwRegBuffer_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
using (Brush hBr = new SolidBrush(hdr))
{
e.Graphics.FillRectangle(hBr, e.Bounds);
e.DrawText();
}
}
}
}

View File

@ -1,60 +0,0 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -1,7 +1,7 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16 # Visual Studio Version 17
VisualStudioVersion = 16.0.31205.134 VisualStudioVersion = 17.0.32112.339
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StockInfoCore", "StockInfoCore\StockInfoCore.csproj", "{99122CA3-5625-4004-BED6-5423873FACAC}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StockInfoCore", "StockInfoCore\StockInfoCore.csproj", "{99122CA3-5625-4004-BED6-5423873FACAC}"
EndProject EndProject
@ -21,7 +21,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StockBL", "StockBL\StockBL.
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StockBL.Interface", "StockBL.Interface\StockBL.Interface.csproj", "{BEAD00C3-74AD-416B-9B36-EBE40DAFF16F}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StockBL.Interface", "StockBL.Interface\StockBL.Interface.csproj", "{BEAD00C3-74AD-416B-9B36-EBE40DAFF16F}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HandleNewWindows", "HandleNewWindows\HandleNewWindows.csproj", "{791F4A63-F1CD-410A-9E9C-071DA8E32880}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BrowserHelper", "BrowserHelper\BrowserHelper.csproj", "{7F507F7A-609F-468F-AA38-41F3240EBF1B}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -65,10 +65,10 @@ Global
{BEAD00C3-74AD-416B-9B36-EBE40DAFF16F}.Debug|Any CPU.Build.0 = Debug|Any CPU {BEAD00C3-74AD-416B-9B36-EBE40DAFF16F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BEAD00C3-74AD-416B-9B36-EBE40DAFF16F}.Release|Any CPU.ActiveCfg = Release|Any CPU {BEAD00C3-74AD-416B-9B36-EBE40DAFF16F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BEAD00C3-74AD-416B-9B36-EBE40DAFF16F}.Release|Any CPU.Build.0 = Release|Any CPU {BEAD00C3-74AD-416B-9B36-EBE40DAFF16F}.Release|Any CPU.Build.0 = Release|Any CPU
{791F4A63-F1CD-410A-9E9C-071DA8E32880}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7F507F7A-609F-468F-AA38-41F3240EBF1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{791F4A63-F1CD-410A-9E9C-071DA8E32880}.Debug|Any CPU.Build.0 = Debug|Any CPU {7F507F7A-609F-468F-AA38-41F3240EBF1B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{791F4A63-F1CD-410A-9E9C-071DA8E32880}.Release|Any CPU.ActiveCfg = Release|Any CPU {7F507F7A-609F-468F-AA38-41F3240EBF1B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{791F4A63-F1CD-410A-9E9C-071DA8E32880}.Release|Any CPU.Build.0 = Release|Any CPU {7F507F7A-609F-468F-AA38-41F3240EBF1B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE