Commit 73e259ef authored by d.hotko's avatar d.hotko

Merge branch 'feature/first_commit' into 'master'

add okei command See merge request !1
parents f1e09bcf f3d7b9f9
################################################################################
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
################################################################################
/.vs
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
[Rr]elease/
x64/
[Bb]in/
[Oo]bj/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.svclog
*.scc
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile
# Visual Studio profiler
*.psess
*.vsp
*.vspx
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# Click-Once directory
publish/
# Publish Web Output
*.Publish.xml
*.pubxml
*.azurePubxml
# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
packages/
## TODO: If the tool you use requires repositories.config, also uncomment the next line
!packages/repositories.config
# Windows Azure Build Output
csx/
*.build.csdef
# Windows Store app package directory
AppPackages/
# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
![Ss]tyle[Cc]op.targets
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.publishsettings
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
App_Data/*.mdf
App_Data/*.ldf
# =========================
# Windows detritus
# =========================
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Mac desktop service store files
.DS_Store
_NCrunch*
\ No newline at end of file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<log4net>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Logs\Example.log"/>
<param name="AppendToFile" value="true"/>
<maxSizeRollBackups value="10"/>
<maximumFileSize value="5MB"/>
<lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d %-5p %m%n"/>
</layout>
</appender>
<logger name="LOGGER">
<appender-ref ref="LogFileAppender"/>
</logger>
</log4net>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
</configuration>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UpdateOKEI
{
class ConstantTables
{
public const string TableOkeiExternal = "[RndSuite].[IdbtUnits]";
public void GetSettingFromOkei()
{
const string Code = "[KOD]";
const string TypeErp = "[TYPE_ERP]";
const string UnitId = "[UNIT_ID]";
const string UnitTp = "[UNIT_TP]";
}
}
}
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UpdateOKEI.Procesing
{
class DataService : IDisposable
{
public SqlConnection SqlConnection = new SqlConnection("data source=rdnl-dev2\\;initial catalog=OpcenterRDnL;Integrated Security = true;");
public DataService()
{
}
public SqlCommand CreateSqlCommand(string command)
{
var sql = new SqlCommand
{
Connection = SqlConnection,
CommandText = command,
CommandType = System.Data.CommandType.Text
};
return sql;
}
public string GetUnitIdByUnit(string unit, string volume)
{
OpenConnection();
string command = "SELECT UNIT_ID FROM [OpcenterRDnL].[RndSuite].[RndtUnit] WHERE UNIT = @Unit and UNIT_TP = @Volume;";
SqlParameter Unit = new SqlParameter
{
ParameterName = "@Unit",
Value = unit
};
SqlParameter Volume = new SqlParameter
{
ParameterName = "@Volume",
Value = volume
};
var sql = CreateSqlCommand(command);
sql.Parameters.Add(Unit);
sql.Parameters.Add(Volume);
decimal id = Decimal.Parse("00");
using (var result = sql.ExecuteReader())
{
while (result.Read())
{
id = Decimal.Parse(result[0].ToString());
}
}
return id.ToString();
}
public string GetUnitIdUnitById(string unit)
{
string command = "SELECT TOP (1000) [KOD] FROM[OpcenterRDnL].[RndSuite].[IdbtUnits] WHERE KOD =@Kod; ";
SqlParameter Kod = new SqlParameter
{
ParameterName = "@Kod",
Value = unit
};
var sql = CreateSqlCommand(command);
sql.Parameters.Add(Kod);
decimal id = Decimal.Parse("00");
using (var result = sql.ExecuteReader())
{
while (result.Read())
{
id = Decimal.Parse(result[0].ToString());
}
}
return id.ToString();
}
public int InsertIntoUnit(string unit, string type, float factor)
{
string command =
"INSERT INTO[RndSuite].[RndtUnit]"+
"([UNIT],[UNIT_TP],[CONV_FACTOR],[LOG_HS],[UNIT_ID])"+
"VALUES(@Unit, @Type, @Factor, '1'"+
", (NEXT VALUE FOR RndSuite.RndsUnitId));";
SqlParameter Unit = new SqlParameter
{
ParameterName = "@Unit",
Value = unit
};
SqlParameter Type = new SqlParameter
{
ParameterName = "@Type",
Value = type
};
SqlParameter Factor = new SqlParameter
{
ParameterName = "@Factor",
Value = factor
};
var sql = CreateSqlCommand(command);
sql.Parameters.Add(Unit);
sql.Parameters.Add(Type);
sql.Parameters.Add(Factor);
int c = sql.ExecuteNonQuery();
return c;
}
public int InsertIntoIdUn(decimal kod, string typeErp, decimal unitId, string type)
{
string command =
"INSERT INTO[RndSuite].[IdbtUnits]" +
"VALUES(@Kod, @TypeErp, @Unit, @Type);";
SqlParameter Unit = new SqlParameter
{
ParameterName = "@Unit",
Value = unitId
};
SqlParameter Type = new SqlParameter
{
ParameterName = "@Type",
Value = type
};
SqlParameter Kod = new SqlParameter
{
ParameterName = "@Kod",
Value = kod
};
SqlParameter TypeErp = new SqlParameter
{
ParameterName = "@TypeErp",
Value = typeErp
};
var sql = CreateSqlCommand(command);
sql.Parameters.Add(Kod);
sql.Parameters.Add(TypeErp);
sql.Parameters.Add(Unit);
sql.Parameters.Add(Type);
int c = sql.ExecuteNonQuery();
return c;
}
public void OpenConnection()
{
if (SqlConnection == null || SqlConnection.State != ConnectionState.Open)
{
try
{
SqlConnection.Open();
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace);
}
}
}
public void Dispose()
{
try
{
if (SqlConnection != null)
{
SqlConnection.Close();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
SqlConnection = null;
}
}
}
}
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("UpdateOKEI")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UpdateOKEI")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[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("590e210b-7f26-4174-8612-f7fbcdb5be64")]
// 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")]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UpdateOKEI
{
class RecordNew
{
public string A0 { get; set; }
public string A1 { get; set; }
public string A2 { get; set; }
public string A3 { get; set; }
public string A4 { get; set; }
public string A5 { get; set; }
public string A6 { get; set; }
public RecordNew(string a0, string a1, string a2, string a3, string a4, string a5, string a6)
{
A0 = a0;//RndtUnitLang.UNIT
A1 = a1;//RndtUnitLang.Lang_ID
A2 = a2;//RndtUnit.UNIT
A3 = a3;//RndtUnit.CONV_FACTOR
A4 = a4;//RndtUnit.CONV_FACTOR
A5 = a5;//UNIT_ID
A6 = a6;//UNIT_TP
}
public override string ToString()
{
return A5 + " " + A6;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UpdateOKEI
{
class RecordOld
{
public string A0 { get; }
public string A1 { get; }
public string A2 { get; }
public string A3 { get; }
public string A4 { get; }
public string A5 { get; }
public string A6 { get; }
public string A7 { get; }
public string A8 { get; }
public string A9 { get; }
public RecordOld(string a0, string a1, string a2, string a3, string a4, string a5, string a6, string a7, string a8, string a9)
{
A0 = a0;//КодЧисловой
A1 = a1;//Наименование
A2 = a2;//УсловноеОбозначениеНациональное
A3 = a3;//УсловноеОбозначениеМеждународное
A4 = a4;//КодовоеБуквенноеОбозначениеНациональное
A5 = a5;//КодовоеБуквенноеОбозначениеМеждународное
A6 = a6;//Числитель
A7 = a7;//Знаменатель
A8 = a8;//ТипИзмеряемойВеличины
A9 = a9;//group
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" 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>{590E210B-7F26-4174-8612-F7FBCDB5BE64}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>UpdateOKEI</RootNamespace>
<AssemblyName>UpdateOKEI</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<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' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject>UpdateOKEI.UpdateOkeiCommand</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net">
<HintPath>..\Dependencies\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
</Reference>
<Reference Include="RnD.Customizations.Interfaces">
<HintPath>..\..\..\Downloads\Customizations\Customizations_\Dependencies\RnD.Customizations.Interfaces.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<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" />
</ItemGroup>
<ItemGroup>
<Compile Include="ConstantTables.cs" />
<Compile Include="Procesing\DataService.cs" />
<Compile Include="RecordNew.cs" />
<Compile Include="RecordOld.cs" />
<Compile Include="UpdateOkeiCommand.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.8">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.8 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
using log4net;
using log4net.Config;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UpdateOKEI.Procesing;
namespace UpdateOKEI
{
class UpdateOkeiCommand
{
static void Main(string[] args)
{
//string path = agrs[0];
string path = @"C:\Users\infodba\Desktop\okei_lims.csv";
//string separator = agrs[1];
string separator = "\t";
var pairs = CreateDictionary();
GetOkeiFromFile(path, separator, pairs);
}
private static Dictionary<string, string> CreateDictionary()
{
Dictionary<string, string> pairs = new Dictionary<string, string>
{
{ "Единицыдлины", "length" },
{ "Единицыплощади", "area" },
{ "Единицыобъема", "volume" },
{ "Единицымассы", "mass" },
{ "Техническиеединицы", "engunits" },
{ "Единицывремени", "time" },
{ "Экономическиеединицы", "econunits" },
};
return pairs;
}
private static void GetOkeiFromFile(string path, string separator, Dictionary<string, string> pairs)
{
DataService db = new DataService();
Logger.InitLogger();//инициализация - требуется один раз в начале
using (var csvReader = new StreamReader(path))
{
List<RecordNew> recs = new List<RecordNew>();
string group = "";
csvReader.ReadLine();
while (!csvReader.EndOfStream)
{
var line = csvReader.ReadLine();
var values = line.Split(Char.Parse(separator));
//Console.WriteLine(line);
if (values[0].Equals("") || values.Length != 9)
{
group = values[1];
continue;
}
else
{
pairs.TryGetValue(group, out string value);
string id = db.GetUnitIdByUnit(values[3], value);
if (id.Equals("0"))
{
float convert = 1.0f;
//if (float.TryParse(values[6], out float t1) &&
//float.TryParse(values[7], out float t2))
//{
// convert = t1 / t2;
//}
if(values[6].Equals("") || values[7].Equals("") || values[8].Equals(""))
{
Logger.Log.Info("object from OKEI with kod " + values[0] + " had mistakes");
Logger.Log.Error(">>" + values[6] + ": is numerator correct?");
Logger.Log.Error(">>" + values[7] + ": is denumerator correct?");
Logger.Log.Error(">>" + values[8] + ": is type correct?");
continue;
}
Console.WriteLine(convert);
//db.
db.InsertIntoUnit(values[3], value, convert);
id = db.GetUnitIdByUnit(values[3], value);
}
string code = db.GetUnitIdUnitById(values[0]);
if (code.Equals("0"))
{
db.InsertIntoIdUn(decimal.Parse(values[0]), values[8], decimal.Parse(id), value);
}
}
}
}
}
}
public static class Logger
{
private static ILog log = LogManager.GetLogger("LOGGER");
public static ILog Log
{
get { return log; }
}
public static void InitLogger()
{
XmlConfigurator.Configure();
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment