Add project files.
This commit is contained in:
269
Maser.Feanor.Biz/Calibrations.cs
Normal file
269
Maser.Feanor.Biz/Calibrations.cs
Normal file
@@ -0,0 +1,269 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Maser.Feanor.Model;
|
||||
using System.Data.SqlClient;
|
||||
using System.Globalization;
|
||||
|
||||
|
||||
namespace Maser.Feanor.Biz
|
||||
{
|
||||
public class Calibrations
|
||||
{
|
||||
public Calibration GetByPK(Int32 PK)
|
||||
{
|
||||
string query = String.Format("Select * from Calibrations where PK = {0}", PK);
|
||||
try
|
||||
{
|
||||
return GetByQuery(query);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<Calibration> GetBySensorPK(Int32 SensorPK)
|
||||
{
|
||||
// Return all calibrations of sensor
|
||||
string query = String.Format("Select * from Calibrations where SensorPK = {0} order by Creation desc", SensorPK);
|
||||
try
|
||||
{
|
||||
return GetListByQuery(query);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Calibration GetLastCreatedBySensorPK(Int32 SensorPK)
|
||||
{
|
||||
string query = String.Format("Select top 1 * from Calibrations where SensorPK = {0} order by Creation desc", SensorPK);
|
||||
try
|
||||
{
|
||||
return GetByQuery(query);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public bool Equal(Calibration A, Calibration B)
|
||||
{
|
||||
// Not equal when values, release or expiry differs
|
||||
// Values can differ 0.01% and still be equal
|
||||
|
||||
if (A.Release != B.Release)
|
||||
return false;
|
||||
|
||||
if (A.Expiry != B.Expiry)
|
||||
return false;
|
||||
|
||||
if (A.Coefficients.Length != B.Coefficients.Length)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < A.Coefficients.Length; i++)
|
||||
{
|
||||
if (B.Coefficients[i] != 0)
|
||||
{
|
||||
double d = Math.Abs(A.Coefficients[i] / B.Coefficients[i] - 1);
|
||||
|
||||
|
||||
if (Math.Abs(A.Coefficients[i] / B.Coefficients[i] - 1) > 0.0000001)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
if (A.Coefficients[i] != 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public Int32 Add(Calibration calibration)
|
||||
{
|
||||
double c0 = calibration.Coefficients[0];
|
||||
double c1 = calibration.Coefficients[1];
|
||||
double c2 = calibration.Coefficients[2];
|
||||
double c3 = calibration.Coefficients[3];
|
||||
|
||||
double X1 = calibration.Xvalues[0];
|
||||
double X2 = calibration.Xvalues[1];
|
||||
double X3 = calibration.Xvalues[2];
|
||||
double X4 = calibration.Xvalues[3];
|
||||
|
||||
//string query = String.Format("INSERT INTO Calibrations (SensorPK, Release, Expiry, Creation, c0, c1, c2, c3, U) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}');", calibration.SensorPK, calibration.Release.FormatSQL(),calibration.Expiry.FormatSQL(), calibration.Creation.FormatSQL(), c0,c1,c2,c3, calibration.Uncertainty);
|
||||
string query = String.Format("INSERT INTO Calibrations (SensorPK, Release, Expiry, Creation, c0, c1, c2, c3, U, X1, X2, X3, X4) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}');", calibration.SensorPK, calibration.Release.FormatSQL(), calibration.Expiry.FormatSQL(), calibration.Creation.FormatSQL(), c0, c1, c2, c3, calibration.Uncertainty,X1,X2,X3,X4);
|
||||
|
||||
query += "SELECT SCOPE_IDENTITY();";
|
||||
|
||||
SqlConnection myConnection = new SqlConnection(Properties.Settings.Default.FeanorConnStr);
|
||||
myConnection.Open();
|
||||
try
|
||||
{
|
||||
SqlCommand myCommand = new SqlCommand(query, myConnection);
|
||||
return Int32.Parse(myCommand.ExecuteScalar().ToString());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
myConnection.Close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private Calibration GetByQuery(string query)
|
||||
{
|
||||
|
||||
Calibration result = null;
|
||||
SqlConnection myConnection = new SqlConnection(Properties.Settings.Default.FeanorConnStr);
|
||||
SqlDataReader myReader = null;
|
||||
try
|
||||
{
|
||||
myConnection.Open();
|
||||
|
||||
SqlCommand myCommand = new SqlCommand(query, myConnection);
|
||||
myReader = myCommand.ExecuteReader();
|
||||
if (myReader.HasRows)
|
||||
{
|
||||
myReader.Read();
|
||||
|
||||
result = FromSqlDataReader(myReader);
|
||||
|
||||
//Console.WriteLine(result);
|
||||
}
|
||||
|
||||
// Console.WriteLine(myReader.FieldCount);
|
||||
myReader.Close();
|
||||
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Console.WriteLine(e);
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
myConnection.Close(); // Martijn
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
https://msdn.microsoft.com/en-us/library/haa3afyz(v=vs.110).aspx
|
||||
Do not call Close or Dispose on a Connection, a DataReader, or any other managed object in the Finalize method of your class.
|
||||
In a finalizer, only release unmanaged resources that your class owns directly.
|
||||
If your class does not own any unmanaged resources, do not include a Finalize method in your class definition.
|
||||
For more information, see Garbage Collection.
|
||||
*/
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private List<Calibration> GetListByQuery(string query)
|
||||
{
|
||||
List<Calibration> result = new List<Calibration>();
|
||||
SqlDataReader myReader = null;
|
||||
SqlConnection myConnection = new SqlConnection(Properties.Settings.Default.FeanorConnStr);
|
||||
|
||||
try
|
||||
{
|
||||
myConnection.Open();
|
||||
|
||||
SqlCommand myCommand = new SqlCommand(query, myConnection);
|
||||
myReader = myCommand.ExecuteReader();
|
||||
if (myReader.HasRows)
|
||||
{
|
||||
while (myReader.Read())
|
||||
{
|
||||
result.Add(FromSqlDataReader(myReader));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
myReader.Close();
|
||||
myConnection.Close(); // Martijn
|
||||
/*
|
||||
https://msdn.microsoft.com/en-us/library/haa3afyz(v=vs.110).aspx
|
||||
Do not call Close or Dispose on a Connection, a DataReader, or any other managed object in the Finalize method of your class.
|
||||
In a finalizer, only release unmanaged resources that your class owns directly.
|
||||
If your class does not own any unmanaged resources, do not include a Finalize method in your class definition.
|
||||
For more information, see Garbage Collection.
|
||||
*/
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private Calibration FromSqlDataReader(SqlDataReader myReader)
|
||||
{
|
||||
double c0 = (double)myReader.GetFloat(5);
|
||||
double c1 = (double)myReader.GetFloat(6);
|
||||
double c2 = (double)myReader.GetFloat(7);
|
||||
double c3 = (double)myReader.GetFloat(8);
|
||||
double U = (double)myReader.GetFloat(9);
|
||||
double X1 = (double)myReader.GetFloat(10);
|
||||
double X2 = (double)myReader.GetFloat(11);
|
||||
double X3 = (double)myReader.GetFloat(12);
|
||||
double X4 = (double)myReader.GetFloat(13);
|
||||
double[] c = new double[4] { c0, c1, c2, c3 };
|
||||
double[] Xvalues = new double[4] { X1, X2, X3, X4 };
|
||||
Calibration result = new Calibration(
|
||||
myReader.GetInt32(0),
|
||||
myReader.GetInt32(1),
|
||||
myReader.GetDateTime(2),
|
||||
myReader.GetDateTime(3),
|
||||
myReader.GetDateTime(4),
|
||||
c,
|
||||
U,
|
||||
Xvalues
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static class StringExtenions
|
||||
{
|
||||
public static bool TryParseToDouble(this String s, out double value)
|
||||
{
|
||||
value = 0;
|
||||
try
|
||||
{
|
||||
NumberStyles styles = NumberStyles.AllowExponent | NumberStyles.Number;
|
||||
value = double.Parse(s, styles);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
15
Maser.Feanor.Biz/Chamber.Extensions.cs
Normal file
15
Maser.Feanor.Biz/Chamber.Extensions.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
|
||||
|
||||
namespace Maser.Feanor.Biz
|
||||
{
|
||||
public static class ChamberExtensions
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
228
Maser.Feanor.Biz/Chambers.cs
Normal file
228
Maser.Feanor.Biz/Chambers.cs
Normal file
@@ -0,0 +1,228 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using System.Collections.ObjectModel;
|
||||
using Maser.Feanor.Model;
|
||||
using System.Data.SqlClient;
|
||||
using System.Drawing;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
Table Chambers in DB should has fields:
|
||||
int PK
|
||||
int MIDS
|
||||
varchar(255) Description
|
||||
varchar(15) Network
|
||||
bit Active
|
||||
*/
|
||||
|
||||
|
||||
namespace Maser.Feanor.Biz
|
||||
{
|
||||
|
||||
public class Chambers
|
||||
{
|
||||
public Chamber GetByPK(Int32 PK)
|
||||
{
|
||||
string query = String.Format("Select * from Chambers where PK = {0}", PK);
|
||||
try
|
||||
{
|
||||
return GetByQuery(query);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public Chamber GetByMIDS(Int32 MIDS)
|
||||
{
|
||||
string query = String.Format("Select * from Chambers where MIDS = {0}", MIDS);
|
||||
try
|
||||
{
|
||||
return GetByQuery(query);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Chamber> GetAllActive()
|
||||
{
|
||||
string query = "Select * from Chambers where Active = 1 ORDER by MIDS ASC";
|
||||
try
|
||||
{
|
||||
return GetListByQuery(query);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Chamber> GetAll()
|
||||
{
|
||||
string query = "Select * from Chambers ORDER by MIDS ASC";
|
||||
try
|
||||
{
|
||||
return GetListByQuery(query);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean Delete(Chamber chamber)
|
||||
{
|
||||
try
|
||||
{
|
||||
chamber.Active = false;
|
||||
return Modify(chamber);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Exists(Chamber chamber)
|
||||
{
|
||||
try
|
||||
{
|
||||
return (GetByPK(chamber.PK) != null);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool Modify(Chamber chamber)
|
||||
{
|
||||
string query = String.Format("UPDATE Chambers SET MIDS='{0}', Description='{1}', Interval='{2}', Network='{3}', ServerType='{4}', Active='{5}', RS485='{6}', HumidityChamber='{7}' WHERE PK={8};", chamber.MIDS, chamber.Description,chamber.Interval, chamber.Network, (int)chamber.ServerType, chamber.Active,chamber.RS485, chamber.Humidity, chamber.PK);
|
||||
|
||||
try
|
||||
{
|
||||
SqlConnection myConnection = new SqlConnection(Properties.Settings.Default.FeanorConnStr);
|
||||
myConnection.Open();
|
||||
SqlCommand myCommand = new SqlCommand(query, myConnection);
|
||||
myCommand.ExecuteNonQuery();
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Int32 Add(Chamber chamber)
|
||||
{
|
||||
string query = String.Format("INSERT INTO Chambers (MIDS, Description, Interval, Network, ServerType, Active, RS485, HumidityChamber) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}');", chamber.MIDS, chamber.Description, chamber.Interval, chamber.Network, (int)chamber.ServerType, chamber.Active, chamber.RS485, chamber.Humidity);
|
||||
query += "SELECT SCOPE_IDENTITY();";
|
||||
|
||||
try
|
||||
{
|
||||
SqlConnection myConnection = new SqlConnection(Properties.Settings.Default.FeanorConnStr);
|
||||
myConnection.Open();
|
||||
SqlCommand myCommand = new SqlCommand(query, myConnection);
|
||||
return Int32.Parse(myCommand.ExecuteScalar().ToString());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private Chamber GetByQuery(string query)
|
||||
{
|
||||
Chamber result = null;
|
||||
SqlConnection myConnection = new SqlConnection(Properties.Settings.Default.FeanorConnStr);
|
||||
SqlDataReader myReader = null;
|
||||
try
|
||||
{
|
||||
myConnection.Open();
|
||||
|
||||
SqlCommand myCommand = new SqlCommand(query, myConnection);
|
||||
myReader = myCommand.ExecuteReader();
|
||||
if (myReader.HasRows)
|
||||
{
|
||||
myReader.Read();
|
||||
result = new Chamber(myReader.GetInt32(0), myReader.GetInt32(1), myReader.GetString(2), myReader.GetInt32(3), myReader.GetString(4), (ServerType)myReader.GetInt32(5), myReader.GetBoolean(6), myReader.GetBoolean(7), myReader.GetBoolean(8));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
myReader.Close();
|
||||
myConnection.Close();
|
||||
/*
|
||||
https://msdn.microsoft.com/en-us/library/haa3afyz(v=vs.110).aspx
|
||||
Do not call Close or Dispose on a Connection, a DataReader, or any other managed object in the Finalize method of your class.
|
||||
In a finalizer, only release unmanaged resources that your class owns directly.
|
||||
If your class does not own any unmanaged resources, do not include a Finalize method in your class definition.
|
||||
For more information, see Garbage Collection.
|
||||
*/
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<Chamber> GetListByQuery(string query)
|
||||
{
|
||||
List<Chamber> result = new List<Chamber>();
|
||||
SqlConnection myConnection = new SqlConnection(Properties.Settings.Default.FeanorConnStr);
|
||||
|
||||
SqlDataReader myReader = null;
|
||||
try
|
||||
{
|
||||
myConnection.Open();
|
||||
|
||||
SqlCommand myCommand = new SqlCommand(query, myConnection);
|
||||
myReader = myCommand.ExecuteReader();
|
||||
if (myReader.HasRows)
|
||||
{
|
||||
while (myReader.Read())
|
||||
{
|
||||
result.Add(new Chamber(myReader.GetInt32(0), myReader.GetInt32(1), myReader.GetString(2), myReader.GetInt32(3), myReader.GetString(4), (ServerType)myReader.GetInt32(5), myReader.GetBoolean(6), myReader.GetBoolean(7), myReader.GetBoolean(8)));
|
||||
}
|
||||
}
|
||||
myReader.Close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
// myReader.Close();
|
||||
/*
|
||||
https://msdn.microsoft.com/en-us/library/haa3afyz(v=vs.110).aspx
|
||||
Do not call Close or Dispose on a Connection, a DataReader, or any other managed object in the Finalize method of your class.
|
||||
In a finalizer, only release unmanaged resources that your class owns directly.
|
||||
If your class does not own any unmanaged resources, do not include a Finalize method in your class definition.
|
||||
For more information, see Garbage Collection.
|
||||
*/
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
BIN
Maser.Feanor.Biz/M.ico
Normal file
BIN
Maser.Feanor.Biz/M.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.5 KiB |
167
Maser.Feanor.Biz/Maser.Feanor.Biz.csproj
Normal file
167
Maser.Feanor.Biz/Maser.Feanor.Biz.csproj
Normal file
@@ -0,0 +1,167 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{316710E0-2143-44CD-8779-A833A2987174}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Maser.Feanor.Biz</RootNamespace>
|
||||
<AssemblyName>Maser.Feanor.Biz</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ApplicationIcon>M.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="HarfBuzzSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\HarfBuzzSharp.7.3.0.3\lib\net462\HarfBuzzSharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="LiveCharts, Version=0.9.7.0, Culture=neutral, PublicKeyToken=0bc1f845d1ebb8df, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\LiveCharts.0.9.7\lib\net45\LiveCharts.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="LiveCharts.WinForms, Version=0.9.7.1, Culture=neutral, PublicKeyToken=0bc1f845d1ebb8df, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\LiveCharts.WinForms.0.9.7.1\lib\net45\LiveCharts.WinForms.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="LiveCharts.Wpf, Version=0.9.7.0, Culture=neutral, PublicKeyToken=0bc1f845d1ebb8df, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\LiveCharts.Wpf.0.9.7\lib\net45\LiveCharts.Wpf.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="OpenTK, Version=3.1.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\OpenTK.3.1.0\lib\net20\OpenTK.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="OpenTK.GLControl, Version=3.1.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\OpenTK.GLControl.3.1.0\lib\net20\OpenTK.GLControl.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
<Reference Include="ScottPlot, Version=5.0.53.0, Culture=neutral, PublicKeyToken=86698dc10387c39e, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ScottPlot.5.0.53\lib\net462\ScottPlot.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ScottPlot.WinForms, Version=5.0.53.0, Culture=neutral, PublicKeyToken=86698dc10387c39e, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ScottPlot.WinForms.5.0.53\lib\net462\ScottPlot.WinForms.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SkiaSharp, Version=2.88.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SkiaSharp.2.88.9\lib\net462\SkiaSharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SkiaSharp.HarfBuzz, Version=2.88.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SkiaSharp.HarfBuzz.2.88.9\lib\net462\SkiaSharp.HarfBuzz.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SkiaSharp.Views.Desktop.Common, Version=2.88.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SkiaSharp.Views.Desktop.Common.2.88.9\lib\net462\SkiaSharp.Views.Desktop.Common.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SkiaSharp.Views.WindowsForms, Version=2.88.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SkiaSharp.Views.WindowsForms.2.88.9\lib\net462\SkiaSharp.Views.WindowsForms.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Drawing.Common, Version=4.0.0.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Drawing.Common.4.7.3\lib\net461\System.Drawing.Common.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xaml" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="WindowsBase" />
|
||||
<Reference Include="WindowsFormsIntegration" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Calibrations.cs" />
|
||||
<Compile Include="Chamber.Extensions.cs" />
|
||||
<Compile Include="Results.cs" />
|
||||
<Compile Include="Sensors.cs" />
|
||||
<Compile Include="Chambers.cs" />
|
||||
<Compile Include="Projects.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="SQLmethods.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Maser.Feanor\Maser.Feanor.Model.csproj">
|
||||
<Project>{f96ec5eb-647c-405e-934f-08df688f55f8}</Project>
|
||||
<Name>Maser.Feanor.Model</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="OpenTK.dll.config" />
|
||||
<None Include="packages.config" />
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="M.ico" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="..\packages\HarfBuzzSharp.NativeAssets.macOS.7.3.0.3\build\net462\HarfBuzzSharp.NativeAssets.macOS.targets" Condition="Exists('..\packages\HarfBuzzSharp.NativeAssets.macOS.7.3.0.3\build\net462\HarfBuzzSharp.NativeAssets.macOS.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\HarfBuzzSharp.NativeAssets.macOS.7.3.0.3\build\net462\HarfBuzzSharp.NativeAssets.macOS.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\HarfBuzzSharp.NativeAssets.macOS.7.3.0.3\build\net462\HarfBuzzSharp.NativeAssets.macOS.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\HarfBuzzSharp.NativeAssets.Win32.7.3.0.3\build\net462\HarfBuzzSharp.NativeAssets.Win32.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\HarfBuzzSharp.NativeAssets.Win32.7.3.0.3\build\net462\HarfBuzzSharp.NativeAssets.Win32.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\SkiaSharp.NativeAssets.macOS.2.88.9\build\net462\SkiaSharp.NativeAssets.macOS.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\SkiaSharp.NativeAssets.macOS.2.88.9\build\net462\SkiaSharp.NativeAssets.macOS.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\SkiaSharp.NativeAssets.Win32.2.88.9\build\net462\SkiaSharp.NativeAssets.Win32.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\SkiaSharp.NativeAssets.Win32.2.88.9\build\net462\SkiaSharp.NativeAssets.Win32.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\HarfBuzzSharp.NativeAssets.Linux.7.3.0.3\build\net462\HarfBuzzSharp.NativeAssets.Linux.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\HarfBuzzSharp.NativeAssets.Linux.7.3.0.3\build\net462\HarfBuzzSharp.NativeAssets.Linux.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\SkiaSharp.NativeAssets.Linux.NoDependencies.2.88.9\build\net462\SkiaSharp.NativeAssets.Linux.NoDependencies.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\SkiaSharp.NativeAssets.Linux.NoDependencies.2.88.9\build\net462\SkiaSharp.NativeAssets.Linux.NoDependencies.targets'))" />
|
||||
</Target>
|
||||
<Import Project="..\packages\HarfBuzzSharp.NativeAssets.Win32.7.3.0.3\build\net462\HarfBuzzSharp.NativeAssets.Win32.targets" Condition="Exists('..\packages\HarfBuzzSharp.NativeAssets.Win32.7.3.0.3\build\net462\HarfBuzzSharp.NativeAssets.Win32.targets')" />
|
||||
<Import Project="..\packages\SkiaSharp.NativeAssets.macOS.2.88.9\build\net462\SkiaSharp.NativeAssets.macOS.targets" Condition="Exists('..\packages\SkiaSharp.NativeAssets.macOS.2.88.9\build\net462\SkiaSharp.NativeAssets.macOS.targets')" />
|
||||
<Import Project="..\packages\SkiaSharp.NativeAssets.Win32.2.88.9\build\net462\SkiaSharp.NativeAssets.Win32.targets" Condition="Exists('..\packages\SkiaSharp.NativeAssets.Win32.2.88.9\build\net462\SkiaSharp.NativeAssets.Win32.targets')" />
|
||||
<Import Project="..\packages\HarfBuzzSharp.NativeAssets.Linux.7.3.0.3\build\net462\HarfBuzzSharp.NativeAssets.Linux.targets" Condition="Exists('..\packages\HarfBuzzSharp.NativeAssets.Linux.7.3.0.3\build\net462\HarfBuzzSharp.NativeAssets.Linux.targets')" />
|
||||
<Import Project="..\packages\SkiaSharp.NativeAssets.Linux.NoDependencies.2.88.9\build\net462\SkiaSharp.NativeAssets.Linux.NoDependencies.targets" Condition="Exists('..\packages\SkiaSharp.NativeAssets.Linux.NoDependencies.2.88.9\build\net462\SkiaSharp.NativeAssets.Linux.NoDependencies.targets')" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
25
Maser.Feanor.Biz/OpenTK.dll.config
Normal file
25
Maser.Feanor.Biz/OpenTK.dll.config
Normal file
@@ -0,0 +1,25 @@
|
||||
<configuration>
|
||||
<dllmap os="linux" dll="opengl32.dll" target="libGL.so.1"/>
|
||||
<dllmap os="linux" dll="glu32.dll" target="libGLU.so.1"/>
|
||||
<dllmap os="linux" dll="openal32.dll" target="libopenal.so.1"/>
|
||||
<dllmap os="linux" dll="alut.dll" target="libalut.so.0"/>
|
||||
<dllmap os="linux" dll="opencl.dll" target="libOpenCL.so"/>
|
||||
<dllmap os="linux" dll="libX11" target="libX11.so.6"/>
|
||||
<dllmap os="linux" dll="libXi" target="libXi.so.6"/>
|
||||
<dllmap os="linux" dll="SDL2.dll" target="libSDL2-2.0.so.0"/>
|
||||
<dllmap os="osx" dll="opengl32.dll" target="/System/Library/Frameworks/OpenGL.framework/OpenGL"/>
|
||||
<dllmap os="osx" dll="openal32.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
|
||||
<dllmap os="osx" dll="alut.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
|
||||
<dllmap os="osx" dll="libGLES.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
|
||||
<dllmap os="osx" dll="libGLESv1_CM.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
|
||||
<dllmap os="osx" dll="libGLESv2.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
|
||||
<dllmap os="osx" dll="opencl.dll" target="/System/Library/Frameworks/OpenCL.framework/OpenCL"/>
|
||||
<dllmap os="osx" dll="SDL2.dll" target="libSDL2.dylib"/>
|
||||
<!-- XQuartz compatibility (X11 on Mac) -->
|
||||
<dllmap os="osx" dll="libGL.so.1" target="/usr/X11/lib/libGL.dylib"/>
|
||||
<dllmap os="osx" dll="libX11" target="/usr/X11/lib/libX11.dylib"/>
|
||||
<dllmap os="osx" dll="libXcursor.so.1" target="/usr/X11/lib/libXcursor.dylib"/>
|
||||
<dllmap os="osx" dll="libXi" target="/usr/X11/lib/libXi.dylib"/>
|
||||
<dllmap os="osx" dll="libXinerama" target="/usr/X11/lib/libXinerama.dylib"/>
|
||||
<dllmap os="osx" dll="libXrandr.so.2" target="/usr/X11/lib/libXrandr.dylib"/>
|
||||
</configuration>
|
||||
292
Maser.Feanor.Biz/Projects.cs
Normal file
292
Maser.Feanor.Biz/Projects.cs
Normal file
@@ -0,0 +1,292 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Maser.Feanor.Model;
|
||||
using System.Data.SqlClient;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
namespace Maser.Feanor.Biz
|
||||
{
|
||||
public enum ProjectStatus
|
||||
{
|
||||
InProgress,
|
||||
Finished,
|
||||
FinishedLastMonth,
|
||||
FinishedLastWeek,
|
||||
None
|
||||
}
|
||||
|
||||
|
||||
public class Projects
|
||||
{
|
||||
public Projects() { }
|
||||
|
||||
public Project GetByPK(Int32 Project_PK)
|
||||
{
|
||||
string query = String.Format("Select * from Projects where PK = {0}", Project_PK);
|
||||
try
|
||||
{
|
||||
return GetByQuery(query);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Project> GetAllActive()
|
||||
{
|
||||
string query = String.Format("Select * from Projects WHERE Stop < '2000-01-01' order by Project ASC"); // PROJECT active if stop-date is in past (stop date == null (not set))
|
||||
try
|
||||
{
|
||||
return GetListByQuery(query);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Project> GetAllFinished()
|
||||
{
|
||||
string query = String.Format("Select * from Projects WHERE Stop > '2000-01-01' order by Project ASC"); // PROJECT finished if stop-date != null (so stop-date is set)
|
||||
try
|
||||
{
|
||||
return GetListByQuery(query);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Project> GetAllFinishedLastMonth()
|
||||
{
|
||||
string query = String.Format("SELECT * FROM Projects WHERE Stop > DATEADD(MONTH, -1, GETDATE()) ORDER BY Project ASC;");
|
||||
try
|
||||
{
|
||||
return GetListByQuery(query);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Project> GetAllFinishedLastWeek()
|
||||
{
|
||||
string query = String.Format("SELECT * FROM Projects WHERE Stop > DATEADD(WEEK, -1, GETDATE()) ORDER BY Project ASC;");
|
||||
try
|
||||
{
|
||||
return GetListByQuery(query);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<Project> GetAll()
|
||||
{
|
||||
string query = String.Format("Select * from Projects order by Project ASC");
|
||||
try
|
||||
{
|
||||
return GetListByQuery(query);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<Project> GetByMIDS(Int32 Project)
|
||||
{
|
||||
string query = String.Format("Select * from Projects where Project = {0}", Project);
|
||||
try
|
||||
{
|
||||
return GetListByQuery(query);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int Add(Project p)
|
||||
{
|
||||
string query = "INSERT INTO Projects ";
|
||||
query += "(Chamber, Start, Stop, Project, ProjectDescription, SubProject, SubProjectDescription, Step, StepDescription, Customer)";
|
||||
query += " VALUES ";
|
||||
query += String.Format("('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}'); ", p.Chamber, p.Start.FormatSQL(), p.Stop.FormatSQL(), p.ProjectID, p.ProjectDescription, p.SubProject, p.SubProjectDescription, p.Step, p.StepDescription, p.Customer);
|
||||
query += "SELECT SCOPE_IDENTITY();";
|
||||
try
|
||||
{
|
||||
SqlConnection myConnection = new SqlConnection(Properties.Settings.Default.FeanorConnStr);
|
||||
myConnection.Open();
|
||||
SqlCommand myCommand = new SqlCommand(query, myConnection);
|
||||
return Int32.Parse(myCommand.ExecuteScalar().ToString());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Boolean Modify(Project p)
|
||||
{
|
||||
string query = "UPDATE Projects SET ";
|
||||
query += String.Format("Chamber='{0}',", p.Chamber);
|
||||
query += String.Format("Start='{0}',", p.Start.FormatSQL());
|
||||
query += String.Format("Stop='{0}',", p.Stop.FormatSQL());
|
||||
query += String.Format("Project='{0}',", p.ProjectID);
|
||||
query += String.Format("ProjectDescription='{0}',", p.ProjectDescription);
|
||||
query += String.Format("SubProject='{0}',", p.SubProject);
|
||||
query += String.Format("SubProjectDescription='{0}',", p.SubProjectDescription);
|
||||
query += String.Format("Step='{0}',", p.Step);
|
||||
query += String.Format("StepDescription='{0}',", p.StepDescription);
|
||||
query += String.Format("Customer='{0}'", p.Customer);
|
||||
query += String.Format(" WHERE PK={0};", p.PK);
|
||||
|
||||
try
|
||||
{
|
||||
SqlConnection myConnection = new SqlConnection(Properties.Settings.Default.FeanorConnStr);
|
||||
myConnection.Open();
|
||||
SqlCommand myCommand = new SqlCommand(query, myConnection);
|
||||
myCommand.ExecuteNonQuery();
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Project GetByQuery(string query)
|
||||
{
|
||||
Project result = null;
|
||||
SqlDataReader myReader = null;
|
||||
SqlConnection myConnection = new SqlConnection(Properties.Settings.Default.FeanorConnStr);
|
||||
|
||||
try
|
||||
{
|
||||
myConnection.Open();
|
||||
|
||||
SqlCommand myCommand = new SqlCommand(query, myConnection);
|
||||
myReader = myCommand.ExecuteReader();
|
||||
if (myReader.HasRows)
|
||||
{
|
||||
myReader.Read();
|
||||
result = new Project();
|
||||
result.PK = myReader.GetInt32(0);
|
||||
result.Chamber = myReader.GetInt32(1);
|
||||
result.Start = myReader.GetDateTime(2);
|
||||
result.Stop = myReader.GetDateTime(3);
|
||||
result.ProjectID = myReader.GetInt32(4);
|
||||
result.ProjectDescription = myReader.GetString(5);
|
||||
result.SubProject = myReader.GetInt32(6);
|
||||
result.SubProjectDescription = myReader.GetString(7);
|
||||
result.Step = myReader.GetInt32(8);
|
||||
result.StepDescription = myReader.GetString(9);
|
||||
result.Customer = myReader.GetString(10);
|
||||
|
||||
if (result.Stop < new DateTime(2000, 1, 1))
|
||||
result.Stop = null;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
myReader.Close();
|
||||
myConnection.Close();
|
||||
/*
|
||||
https://msdn.microsoft.com/en-us/library/haa3afyz(v=vs.110).aspx
|
||||
Do not call Close or Dispose on a Connection, a DataReader, or any other managed object in the Finalize method of your class.
|
||||
In a finalizer, only release unmanaged resources that your class owns directly.
|
||||
If your class does not own any unmanaged resources, do not include a Finalize method in your class definition.
|
||||
For more information, see Garbage Collection.
|
||||
*/
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<Project> GetListByQuery(string query)
|
||||
{
|
||||
List<Project> result = new List<Project>();
|
||||
SqlDataReader myReader = null;
|
||||
SqlConnection myConnection = new SqlConnection(Properties.Settings.Default.FeanorConnStr);
|
||||
|
||||
try
|
||||
{
|
||||
myConnection.Open();
|
||||
|
||||
SqlCommand myCommand = new SqlCommand(query, myConnection);
|
||||
myReader = myCommand.ExecuteReader();
|
||||
if (myReader.HasRows)
|
||||
{
|
||||
while (myReader.Read())
|
||||
{
|
||||
Project p = new Project();
|
||||
p.PK = myReader.GetInt32(0);
|
||||
p.Chamber = myReader.GetInt32(1);
|
||||
p.Start = myReader.GetDateTime(2);
|
||||
p.Stop = myReader.GetDateTime(3);
|
||||
|
||||
p.ProjectID = myReader.GetInt32(4);
|
||||
p.ProjectDescription = myReader.GetString(5);
|
||||
p.SubProject = myReader.GetInt32(6);
|
||||
p.SubProjectDescription = myReader.GetString(7);
|
||||
p.Step = myReader.GetInt32(8);
|
||||
p.StepDescription = myReader.GetString(9);
|
||||
p.Customer = myReader.GetString(10);
|
||||
|
||||
if (p.Stop < new DateTime(2000, 1, 1))
|
||||
p.Stop = null;
|
||||
|
||||
result.Add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
myReader.Close();
|
||||
myConnection.Close(); // Martijn
|
||||
/*
|
||||
https://msdn.microsoft.com/en-us/library/haa3afyz(v=vs.110).aspx
|
||||
Do not call Close or Dispose on a Connection, a DataReader, or any other managed object in the Finalize method of your class.
|
||||
In a finalizer, only release unmanaged resources that your class owns directly.
|
||||
If your class does not own any unmanaged resources, do not include a Finalize method in your class definition.
|
||||
For more information, see Garbage Collection.
|
||||
*/
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
36
Maser.Feanor.Biz/Properties/AssemblyInfo.cs
Normal file
36
Maser.Feanor.Biz/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Maser.Feanor.Biz")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Maser.Feanor.Biz")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2016")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("316710e0-2143-44cd-8779-a833a2987174")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
37
Maser.Feanor.Biz/Properties/Settings.Designer.cs
generated
Normal file
37
Maser.Feanor.Biz/Properties/Settings.Designer.cs
generated
Normal file
@@ -0,0 +1,37 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Maser.Feanor.Biz.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default {
|
||||
get {
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.ApplicationScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.ConnectionString)]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("Data Source=tcp:192.168.0.241,1434; Initial Catalog = FEANOR; Persist Security Info=True; User " +
|
||||
"ID = sa; Password=resam; connection timeout=15; TrustServerCertificate=True")]
|
||||
public string FeanorConnStr {
|
||||
get {
|
||||
return ((string)(this["FeanorConnStr"]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
14
Maser.Feanor.Biz/Properties/Settings.settings
Normal file
14
Maser.Feanor.Biz/Properties/Settings.settings
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="Maser.Feanor.Biz.Properties" GeneratedClassName="Settings">
|
||||
<Profiles />
|
||||
<Settings>
|
||||
<Setting Name="FeanorConnStr" Type="(Connection string)" Scope="Application">
|
||||
<DesignTimeValue Profile="(Default)"><?xml version="1.0" encoding="utf-16"?>
|
||||
<SerializableConnectionString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||
<ConnectionString>Data Source=.\FEANOR; Initial Catalog = FEANOR; Persist Security Info=True; User ID = sa; Password=resam; connection timeout=15</ConnectionString>
|
||||
<ProviderName>System.Data.SqlClient</ProviderName>
|
||||
</SerializableConnectionString></DesignTimeValue>
|
||||
<Value Profile="(Default)">Data Source=.\FEANOR; Initial Catalog = FEANOR; Persist Security Info=True; User ID = sa; Password=resam; connection timeout=15</Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
||||
312
Maser.Feanor.Biz/Results.cs
Normal file
312
Maser.Feanor.Biz/Results.cs
Normal file
@@ -0,0 +1,312 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
using Maser.Feanor.Model;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
|
||||
|
||||
namespace Maser.Feanor.Biz
|
||||
{
|
||||
public class Results
|
||||
{
|
||||
public Result GetByPK(Int32 PK)
|
||||
{
|
||||
string query = String.Format("Select * from Results where PK = {0}", PK);
|
||||
try
|
||||
{
|
||||
return GetByQuery(query);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<Result> GetByProject(Project project)
|
||||
{
|
||||
List<SqlParameter> parameters = new List<SqlParameter>();
|
||||
parameters.Add(new SqlParameter("@Project_PK", project.PK));
|
||||
try
|
||||
{
|
||||
List<Result> results = GetFromStoredProc("Results_GetByProject", parameters);
|
||||
return results;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<Result> GetByProjectWindow(Int32 Project_PK, Int32 Sensor_PK)
|
||||
{
|
||||
List<SqlParameter> parameters = new List<SqlParameter>();
|
||||
parameters.Add(new SqlParameter("@ProjectPK", Project_PK));
|
||||
parameters.Add(new SqlParameter("@SensorPK", Sensor_PK));
|
||||
try
|
||||
{
|
||||
List<Result> results = GetFromStoredProc("Results_GetByProjectWindow", parameters);
|
||||
return results;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Result> GetByProjectWindowOudeHal(Int32 Project_PK, Int32 Sensor_PK)
|
||||
{
|
||||
List<SqlParameter> parameters = new List<SqlParameter>();
|
||||
parameters.Add(new SqlParameter("@ProjectPK", Project_PK));
|
||||
parameters.Add(new SqlParameter("@SensorPK", Sensor_PK));
|
||||
try
|
||||
{
|
||||
List<Result> results = GetFromStoredProc("ResultsOudeHal_GetByProjectWindow", parameters);
|
||||
return results;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Result GetLastBySensorPK(Int32 sensorPK)
|
||||
{
|
||||
return GetLastBySensorPK(sensorPK, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public Result GetLastBySensorPK(Int32 sensorPK, bool LimitedSearch)
|
||||
{
|
||||
List<SqlParameter> parameters = new List<SqlParameter>();
|
||||
parameters.Add(new SqlParameter("@PK", sensorPK));
|
||||
parameters.Add(new SqlParameter("@LimitedSearch", LimitedSearch ? 1 : 0));
|
||||
try
|
||||
{
|
||||
List<Result> results = GetFromStoredProc("Results_GetLatestBySensorPK", parameters);
|
||||
|
||||
if (results.Count == 0)
|
||||
return null;
|
||||
return results[0];
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("GetLastBySensorPK Error: "+ e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public bool Exists(Result result)
|
||||
{
|
||||
try
|
||||
{
|
||||
return (GetByPK(result.PK) != null);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Add(List<Result> results)
|
||||
{
|
||||
SqlConnection myConnection = new SqlConnection(Properties.Settings.Default.FeanorConnStr);
|
||||
|
||||
try
|
||||
{
|
||||
myConnection.Open();
|
||||
foreach (Result result in results)
|
||||
{
|
||||
|
||||
SqlCommand cmd = new SqlCommand(@"INSERT INTO Results (SensorPK, Value, Timestamp, CalibrationPK) VALUES (@sensorpk, @value, @timestamp, @calibrationpk)", myConnection);
|
||||
{
|
||||
|
||||
cmd.Parameters.AddWithValue("@sensorpk", result.SensorPK);
|
||||
cmd.Parameters.AddWithValue("@value", result.Value);
|
||||
cmd.Parameters.AddWithValue("@timestamp", result.TimeStamp.FormatSQL());
|
||||
cmd.Parameters.AddWithValue("@calibrationpk", result.CalibrationPK);
|
||||
}
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
myConnection.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public void AddOudeHal(List<Result> results)
|
||||
{
|
||||
SqlConnection myConnection = new SqlConnection(Properties.Settings.Default.FeanorConnStr);
|
||||
|
||||
try
|
||||
{
|
||||
myConnection.Open();
|
||||
foreach (Result result in results)
|
||||
{
|
||||
SqlCommand cmd = new SqlCommand(@"INSERT INTO ResultsOudeHal (SensorPK, Value, Timestamp, CalibrationPK) VALUES (@sensorpk, @value, @timestamp, @calibrationpk)", myConnection);
|
||||
{
|
||||
|
||||
cmd.Parameters.AddWithValue("@sensorpk", result.SensorPK);
|
||||
cmd.Parameters.AddWithValue("@value", result.Value);
|
||||
cmd.Parameters.AddWithValue("@timestamp", result.TimeStamp.FormatSQL());
|
||||
cmd.Parameters.AddWithValue("@calibrationpk", result.CalibrationPK);
|
||||
}
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
myConnection.Close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private Result GetByQuery(string query)
|
||||
{
|
||||
Result result = null;
|
||||
SqlConnection myConnection = new SqlConnection(Properties.Settings.Default.FeanorConnStr);
|
||||
SqlDataReader myReader = null;
|
||||
try
|
||||
{
|
||||
myConnection.Open();
|
||||
|
||||
SqlCommand myCommand = new SqlCommand(query, myConnection);
|
||||
myReader = myCommand.ExecuteReader();
|
||||
if (myReader.HasRows)
|
||||
{
|
||||
myReader.Read();
|
||||
result = new Result(myReader.GetInt32(0), myReader.GetInt32(1),(double)myReader.GetFloat(2), myReader.GetDateTime(3), myReader.GetInt32(4));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
myReader.Close();
|
||||
myConnection.Close(); // Martijn
|
||||
/*
|
||||
https://msdn.microsoft.com/en-us/library/haa3afyz(v=vs.110).aspx
|
||||
Do not call Close or Dispose on a Connection, a DataReader, or any other managed object in the Finalize method of your class.
|
||||
In a finalizer, only release unmanaged resources that your class owns directly.
|
||||
If your class does not own any unmanaged resources, do not include a Finalize method in your class definition.
|
||||
For more information, see Garbage Collection.
|
||||
*/
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private List<Result> GetListByQuery(string query)
|
||||
{
|
||||
List<Result> result = new List<Result>();
|
||||
SqlConnection myConnection = new SqlConnection(Properties.Settings.Default.FeanorConnStr);
|
||||
SqlDataReader myReader = null;
|
||||
|
||||
try
|
||||
{
|
||||
myConnection.Open();
|
||||
|
||||
SqlCommand myCommand = new SqlCommand(query, myConnection);
|
||||
myReader = myCommand.ExecuteReader();
|
||||
if (myReader.HasRows)
|
||||
{
|
||||
while (myReader.Read())
|
||||
{
|
||||
result.Add(new Result(myReader.GetInt32(0), myReader.GetInt32(1), (double)myReader.GetFloat(2), myReader.GetDateTime(3), myReader.GetInt32(4)));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
myReader.Close();
|
||||
/*
|
||||
https://msdn.microsoft.com/en-us/library/haa3afyz(v=vs.110).aspx
|
||||
Do not call Close or Dispose on a Connection, a DataReader, or any other managed object in the Finalize method of your class.
|
||||
In a finalizer, only release unmanaged resources that your class owns directly.
|
||||
If your class does not own any unmanaged resources, do not include a Finalize method in your class definition.
|
||||
For more information, see Garbage Collection.
|
||||
*/
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private List<Result> GetFromStoredProc(string procedure, List<SqlParameter> parameters)
|
||||
{
|
||||
List<Result> result = new List<Result>();
|
||||
SqlConnection myConnection = new SqlConnection(Properties.Settings.Default.FeanorConnStr);
|
||||
SqlDataReader myReader = null;
|
||||
|
||||
try
|
||||
{
|
||||
SqlCommand myCommand = new SqlCommand(procedure, myConnection);
|
||||
|
||||
foreach (SqlParameter p in parameters)
|
||||
{
|
||||
myCommand.Parameters.Add(p);
|
||||
}
|
||||
|
||||
myCommand.CommandType = System.Data.CommandType.StoredProcedure;
|
||||
myConnection.Open();
|
||||
myReader = myCommand.ExecuteReader();
|
||||
|
||||
if (myReader.HasRows)
|
||||
{
|
||||
while (myReader.Read())
|
||||
{
|
||||
result.Add(new Result(myReader.GetInt32(0), myReader.GetInt32(1), (double)myReader.GetFloat(2), myReader.GetDateTime(3), myReader.GetInt32(4)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
myReader.Close(); // was er origineel wel
|
||||
|
||||
myConnection.Close(); // was er origineel niet
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
49
Maser.Feanor.Biz/SQLmethods.cs
Normal file
49
Maser.Feanor.Biz/SQLmethods.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Maser.Feanor.Model;
|
||||
|
||||
|
||||
namespace Maser.Feanor.Biz
|
||||
{
|
||||
public static class SQLMethods
|
||||
{
|
||||
public static string FormatSQL(this DateTime? dt)
|
||||
{
|
||||
if (dt == null)
|
||||
return null;
|
||||
|
||||
// SQL format is '2016-12-15 12:24:32.427'
|
||||
return String.Format("{0:yyyy-MM-dd HH:mm:ss:fff}", dt);
|
||||
|
||||
}
|
||||
public static string FormatSQL(this DateTime dt)
|
||||
{
|
||||
// SQL format is '2016-12-15 12:24:32.427'
|
||||
return String.Format("{0:yyyy-MM-dd HH:mm:ss:fff}", dt);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static bool DatabaseOnline(Int32 TimeOutSec)
|
||||
{
|
||||
DateTime dtTimeout = DateTime.Now.AddSeconds(TimeOutSec);
|
||||
while (DateTime.Now < dtTimeout)
|
||||
{
|
||||
try
|
||||
{
|
||||
new Chambers().GetAllActive();
|
||||
return true;
|
||||
}
|
||||
catch { }
|
||||
System.Threading.Thread.Sleep(1000);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
282
Maser.Feanor.Biz/Sensors.cs
Normal file
282
Maser.Feanor.Biz/Sensors.cs
Normal file
@@ -0,0 +1,282 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
using Maser.Feanor.Model;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
|
||||
|
||||
namespace Maser.Feanor.Biz
|
||||
{
|
||||
|
||||
public class Sensors
|
||||
{
|
||||
|
||||
public List<Sensor> GetActiveByChamber(Int32 chamberPK)
|
||||
{
|
||||
string query = string.Format("Select * from Sensors where Enabled = 1 and ChamberPK = {0:0} order by ID", chamberPK);
|
||||
try
|
||||
{
|
||||
return GetListByQuery(query);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool Equal(Sensor A, Sensor B)
|
||||
{
|
||||
// Compare properties that can be changed by user
|
||||
if (A.Description != B.Description)
|
||||
return false;
|
||||
|
||||
if (A.Enabled != B.Enabled)
|
||||
return false;
|
||||
|
||||
|
||||
if (A.ApplyCalibration != B.ApplyCalibration)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public List<Sensor> GetByChamber(int chamberPK)
|
||||
{
|
||||
string query = string.Format("Select * from Sensors where ChamberPK = {0:0} order by ID asc", chamberPK);
|
||||
try
|
||||
{
|
||||
return GetListByQuery(query);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Sensor GetByPK(Int32 PK)
|
||||
{
|
||||
string query = String.Format("Select * from Sensors where PK = {0}", PK);
|
||||
try
|
||||
{
|
||||
return GetByQuery(query);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public Sensor GetByID(Int32 ID, Int32 ChamberPK)
|
||||
{
|
||||
string query = String.Format("Select * from Sensors where ID = {0} AND ChamberPK = {1}", ID, ChamberPK);
|
||||
try
|
||||
{
|
||||
return GetByQuery(query);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Sensor> GetAllActive()
|
||||
{
|
||||
string query = "Select * from Sensors where Enabled = 1";
|
||||
try
|
||||
{
|
||||
return GetListByQuery(query);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Sensor> GetAll()
|
||||
{
|
||||
string query = "Select * from Sensors";
|
||||
try
|
||||
{
|
||||
return GetListByQuery(query);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean Delete(Sensor sensor)
|
||||
{
|
||||
try
|
||||
{
|
||||
sensor.Enabled = false;
|
||||
return Modify(sensor);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Exists(Sensor sensor)
|
||||
{
|
||||
try
|
||||
{
|
||||
return (GetByPK(sensor.PK) != null);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Modify(Sensor sensor)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!Exists(sensor))
|
||||
return false;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
|
||||
string query = String.Format("UPDATE Sensors SET ID='{0}', ChamberPK='{1}', Description='{2}', Type='{3}', Enabled='{4}', ApplyCalibration='{5}' WHERE PK={6};", sensor.ID,sensor.ChamberPK,sensor.Description,(int)sensor.Type,sensor.Enabled,sensor.ApplyCalibration,sensor.PK);
|
||||
try
|
||||
{
|
||||
SqlConnection myConnection = new SqlConnection(Properties.Settings.Default.FeanorConnStr);
|
||||
myConnection.Open();
|
||||
SqlCommand myCommand = new SqlCommand(query, myConnection);
|
||||
myCommand.ExecuteNonQuery();
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Int32 Add(Sensor sensor)
|
||||
{
|
||||
string query = String.Format("INSERT INTO Sensors (ID, ChamberPK, Description, Type, Enabled, ApplyCalibration) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}');", sensor.ID, sensor.ChamberPK, sensor.Description, (int)sensor.Type, sensor.Enabled, sensor.ApplyCalibration);
|
||||
query += "SELECT SCOPE_IDENTITY();";
|
||||
|
||||
SqlConnection myConnection = new SqlConnection(Properties.Settings.Default.FeanorConnStr);
|
||||
myConnection.Open();
|
||||
try
|
||||
{
|
||||
SqlCommand myCommand = new SqlCommand(query, myConnection);
|
||||
return Int32.Parse(myCommand.ExecuteScalar().ToString());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
myConnection.Close();
|
||||
}
|
||||
}
|
||||
|
||||
private Sensor GetByQuery(string query)
|
||||
{
|
||||
Sensor result = null;
|
||||
SqlConnection myConnection = new SqlConnection(Properties.Settings.Default.FeanorConnStr);
|
||||
SqlDataReader myReader = null;
|
||||
try
|
||||
{
|
||||
myConnection.Open();
|
||||
|
||||
SqlCommand myCommand = new SqlCommand(query, myConnection);
|
||||
myReader = myCommand.ExecuteReader();
|
||||
if (myReader.HasRows)
|
||||
{
|
||||
myReader.Read();
|
||||
result = new Sensor(myReader.GetInt32(0), myReader.GetInt32(1), myReader.GetInt32(2), myReader.GetString(3), (SensorType)myReader.GetInt32(4), myReader.GetBoolean(5), myReader.GetBoolean(6));
|
||||
}
|
||||
|
||||
if (myReader != null)
|
||||
{
|
||||
myReader.Close();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
throw e;
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
myConnection.Close(); // Martijn
|
||||
/*
|
||||
https://msdn.microsoft.com/en-us/library/haa3afyz(v=vs.110).aspx
|
||||
Do not call Close or Dispose on a Connection, a DataReader, or any other managed object in the Finalize method of your class.
|
||||
In a finalizer, only release unmanaged resources that your class owns directly.
|
||||
If your class does not own any unmanaged resources, do not include a Finalize method in your class definition.
|
||||
For more information, see Garbage Collection.
|
||||
*/
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<Sensor> GetListByQuery(string query)
|
||||
{
|
||||
List<Sensor> result = new List<Sensor>();
|
||||
SqlConnection myConnection = new SqlConnection(Properties.Settings.Default.FeanorConnStr);
|
||||
|
||||
SqlDataReader myReader = null;
|
||||
try
|
||||
{
|
||||
myConnection.Open();
|
||||
|
||||
SqlCommand myCommand = new SqlCommand(query, myConnection);
|
||||
myReader = myCommand.ExecuteReader();
|
||||
if (myReader.HasRows)
|
||||
{
|
||||
while (myReader.Read())
|
||||
{
|
||||
result.Add(new Sensor(myReader.GetInt32(0), myReader.GetInt32(1), myReader.GetInt32(2), myReader.GetString(3), (SensorType)myReader.GetInt32(4), myReader.GetBoolean(5), myReader.GetBoolean(6)));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (myReader != null)
|
||||
myReader.Close();
|
||||
myConnection.Close(); // Martijn
|
||||
|
||||
/*
|
||||
https://msdn.microsoft.com/en-us/library/haa3afyz(v=vs.110).aspx
|
||||
Do not call Close or Dispose on a Connection, a DataReader, or any other managed object in the Finalize method of your class.
|
||||
In a finalizer, only release unmanaged resources that your class owns directly.
|
||||
If your class does not own any unmanaged resources, do not include a Finalize method in your class definition.
|
||||
For more information, see Garbage Collection.
|
||||
*/
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
8
Maser.Feanor.Biz/app.config
Normal file
8
Maser.Feanor.Biz/app.config
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
</configSections>
|
||||
<connectionStrings>
|
||||
<add name="Maser.Feanor.Biz.Properties.Settings.FeanorConnStr" connectionString="Data Source=.\FEANOR; Initial Catalog = FEANOR; Persist Security Info=True; User ID = sa; Password=resam; connection timeout=15" providerName="System.Data.SqlClient"/>
|
||||
</connectionStrings>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/></startup></configuration>
|
||||
27
Maser.Feanor.Biz/packages.config
Normal file
27
Maser.Feanor.Biz/packages.config
Normal file
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="HarfBuzzSharp" version="7.3.0.3" targetFramework="net472" />
|
||||
<package id="HarfBuzzSharp.NativeAssets.Linux" version="7.3.0.3" targetFramework="net472" />
|
||||
<package id="HarfBuzzSharp.NativeAssets.macOS" version="7.3.0.3" targetFramework="net472" />
|
||||
<package id="HarfBuzzSharp.NativeAssets.Win32" version="7.3.0.3" targetFramework="net472" />
|
||||
<package id="LiveCharts" version="0.9.7" targetFramework="net472" />
|
||||
<package id="LiveCharts.WinForms" version="0.9.7.1" targetFramework="net472" />
|
||||
<package id="LiveCharts.Wpf" version="0.9.7" targetFramework="net472" />
|
||||
<package id="OpenTK" version="3.1.0" targetFramework="net472" />
|
||||
<package id="OpenTK.GLControl" version="3.1.0" targetFramework="net472" />
|
||||
<package id="ScottPlot" version="5.0.53" targetFramework="net472" />
|
||||
<package id="ScottPlot.WinForms" version="5.0.53" targetFramework="net472" />
|
||||
<package id="SkiaSharp" version="2.88.9" targetFramework="net472" />
|
||||
<package id="SkiaSharp.HarfBuzz" version="2.88.9" targetFramework="net472" />
|
||||
<package id="SkiaSharp.NativeAssets.Linux.NoDependencies" version="2.88.9" targetFramework="net472" />
|
||||
<package id="SkiaSharp.NativeAssets.macOS" version="2.88.9" targetFramework="net472" />
|
||||
<package id="SkiaSharp.NativeAssets.Win32" version="2.88.9" targetFramework="net472" />
|
||||
<package id="SkiaSharp.Views.Desktop.Common" version="2.88.9" targetFramework="net472" />
|
||||
<package id="SkiaSharp.Views.WindowsForms" version="2.88.9" targetFramework="net472" />
|
||||
<package id="System.Buffers" version="4.5.1" targetFramework="net472" />
|
||||
<package id="System.Drawing.Common" version="4.7.3" targetFramework="net472" />
|
||||
<package id="System.Memory" version="4.5.5" targetFramework="net472" />
|
||||
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net472" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.3" targetFramework="net472" />
|
||||
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user