Infört Dapper och skrivande av en rad
This commit is contained in:
6
WindowsFormsCore/App.config
Normal file
6
WindowsFormsCore/App.config
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<configuration>
|
||||||
|
<connectionStrings>
|
||||||
|
<add name="DapperDB" connectionString="Data Source=Oemansv7win;Initial Catalog=LottoDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"/>
|
||||||
|
</connectionStrings>
|
||||||
|
</configuration>
|
||||||
@ -4,6 +4,12 @@ namespace WindowsFormsCore.Domain
|
|||||||
{
|
{
|
||||||
public class NumberRow
|
public class NumberRow
|
||||||
{
|
{
|
||||||
|
public NumberRow()
|
||||||
|
{
|
||||||
|
Created = DateTime.Now;
|
||||||
|
}
|
||||||
|
public string Id { get; set; }
|
||||||
|
|
||||||
public byte Number0 { get; set; }
|
public byte Number0 { get; set; }
|
||||||
public byte Number1 { get; set; }
|
public byte Number1 { get; set; }
|
||||||
public byte Number2 { get; set; }
|
public byte Number2 { get; set; }
|
||||||
@ -13,7 +19,7 @@ namespace WindowsFormsCore.Domain
|
|||||||
public byte Number6 { get; set; }
|
public byte Number6 { get; set; }
|
||||||
public byte Number7 { get; set; }
|
public byte Number7 { get; set; }
|
||||||
|
|
||||||
public string KeyString { get; set; }
|
public DateTime Created { get; init; }
|
||||||
|
|
||||||
public void NumbersToKey()
|
public void NumbersToKey()
|
||||||
{
|
{
|
||||||
@ -29,12 +35,12 @@ namespace WindowsFormsCore.Domain
|
|||||||
Number7
|
Number7
|
||||||
};
|
};
|
||||||
var longTmp = BitConverter.ToInt64(arr);
|
var longTmp = BitConverter.ToInt64(arr);
|
||||||
KeyString = longTmp.ToString();
|
Id = longTmp.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void KeyToNumbers()
|
public void KeyToNumbers()
|
||||||
{
|
{
|
||||||
var arr = BitConverter.GetBytes(long.Parse(KeyString));
|
var arr = BitConverter.GetBytes(long.Parse(Id));
|
||||||
Number0 = arr[0];
|
Number0 = arr[0];
|
||||||
Number1 = arr[1];
|
Number1 = arr[1];
|
||||||
Number2 = arr[2];
|
Number2 = arr[2];
|
||||||
|
|||||||
60
WindowsFormsCore/Operations/DBRepo.cs
Normal file
60
WindowsFormsCore/Operations/DBRepo.cs
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
using Dapper;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Data.SqlClient;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using WindowsFormsCore.Domain;
|
||||||
|
using static WindowsFormsCore.Operations.Tools;
|
||||||
|
|
||||||
|
namespace WindowsFormsCore.Operations
|
||||||
|
{
|
||||||
|
public class DBRepo
|
||||||
|
{
|
||||||
|
public static void SaveNumberRow(NumberRow numberRow)
|
||||||
|
{
|
||||||
|
using(IDbConnection cnn = new SqlConnection(GetConnectionString()))
|
||||||
|
{
|
||||||
|
numberRow.NumbersToKey();
|
||||||
|
var p = new DynamicParameters();
|
||||||
|
p.Add("@Id", numberRow.Id);
|
||||||
|
p.Add("@Number1", numberRow.Number1);
|
||||||
|
p.Add("@Number2", numberRow.Number2);
|
||||||
|
p.Add("@Number3", numberRow.Number3);
|
||||||
|
p.Add("@Number4", numberRow.Number4);
|
||||||
|
p.Add("@Number5", numberRow.Number5);
|
||||||
|
p.Add("@Number6", numberRow.Number6);
|
||||||
|
p.Add("@Number7", numberRow.Number7);
|
||||||
|
p.Add("@Created", numberRow.Created);
|
||||||
|
string sql = @"insert into dbo.NumbersTable (
|
||||||
|
Id,
|
||||||
|
Created,
|
||||||
|
Number1,
|
||||||
|
Number2,
|
||||||
|
Number3,
|
||||||
|
Number4,
|
||||||
|
Number5,
|
||||||
|
Number6,
|
||||||
|
Number7
|
||||||
|
)
|
||||||
|
values(
|
||||||
|
@Id,
|
||||||
|
@Created,
|
||||||
|
@Number1,
|
||||||
|
@Number2,
|
||||||
|
@Number3,
|
||||||
|
@Number4,
|
||||||
|
@Number5,
|
||||||
|
@Number6,
|
||||||
|
@Number7
|
||||||
|
)";
|
||||||
|
|
||||||
|
cnn.Execute(sql, p);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
13
WindowsFormsCore/Operations/Tools.cs
Normal file
13
WindowsFormsCore/Operations/Tools.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using System.Configuration;
|
||||||
|
|
||||||
|
namespace WindowsFormsCore.Operations
|
||||||
|
{
|
||||||
|
public class Tools
|
||||||
|
{
|
||||||
|
public static string GetConnectionString(string name = "DapperDB")
|
||||||
|
{
|
||||||
|
return ConfigurationManager.ConnectionStrings[name].ConnectionString;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -7,6 +7,11 @@
|
|||||||
<StartupObject>WindowsFormsCore.Program</StartupObject>
|
<StartupObject>WindowsFormsCore.Program</StartupObject>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Dapper" Version="2.0.78" />
|
||||||
|
<PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Update="Properties\Resources.Designer.cs">
|
<Compile Update="Properties\Resources.Designer.cs">
|
||||||
<DesignTime>True</DesignTime>
|
<DesignTime>True</DesignTime>
|
||||||
|
|||||||
Reference in New Issue
Block a user