Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
v6.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
bdrum committed Nov 7, 2019
1 parent 6cdf779 commit ec2dced
Show file tree
Hide file tree
Showing 12 changed files with 11,301 additions and 11,131 deletions.
3 changes: 3 additions & 0 deletions Extensions/Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

<ItemGroup>
<PackageReference Include="CredentialManagement.Standard" Version="1.0.4" />
<PackageReference Include="CsvHelper" Version="12.2.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.6" />
</ItemGroup>

</Project>
43 changes: 43 additions & 0 deletions Extensions/csv/CSVAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using CsvHelper;
using System.IO;
using System.Linq;
using Extensions.Models;

namespace Extensions.CSV
{
public static class CSVAdapter
{
public static void LoadFileToDb(string pathToFile, string ConnectionString, string countryCode, string clientId, string year, string setId, string setIndex)
{
List<SampleInfo> samples = null;
using (var reader = new StreamReader(pathToFile))
using (var csv = new CsvReader(reader))
{
//csv.Configuration.PrepareHeaderForMatch = (string header, int index) => header.ToLower();
csv.Configuration.ShouldSkipRecord = row => row[0].StartsWith("0");
csv.Configuration.Delimiter = "\t";
try
{
samples = new List<SampleInfo>(csv.GetRecords<SampleInfo>());

samples.ForEach(s => { s.F_Country_Code = countryCode; s.F_Client_Id = clientId; s.F_Year = year; s.F_Sample_Set_Id = setId; s.F_Sample_Set_Index = setIndex; s.A_Sample_ID = s.Number.ToString("d2"); });

using (var ic = new InfoContext(ConnectionString))
{
ic.Samples.AddRange(samples);
ic.SaveChanges();
}


}
catch (Exception ex)
{
;
}
}

}
}
}
29 changes: 29 additions & 0 deletions Extensions/csv/InfoContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore;

namespace Extensions.Models
{
public class InfoContext : DbContext
{
public DbSet<SampleInfo> Samples { get; set; }

private readonly string connectionString;
public InfoContext(string connectionString) : base()
{
this.connectionString = connectionString;
}

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlServer(connectionString);
}
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<SampleInfo>()
.HasKey(s => new { s.F_Country_Code, s.F_Client_Id, s.F_Year, s.F_Sample_Set_Id, s.F_Sample_Set_Index, s.A_Sample_ID });
}
}
}
188 changes: 188 additions & 0 deletions Extensions/csv/SampleInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
using CsvHelper.Configuration.Attributes;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;

namespace Extensions.Models
{
[Table("table_Sample")]
public class SampleInfo
{

[Ignore]
[Key]
public string F_Country_Code { get; set; }
[Ignore]
[Key]
public string F_Client_Id { get; set; }
[Ignore]
[Key]
public string F_Year { get; set; }
[Ignore]
[Key]
public string F_Sample_Set_Id { get; set; }
[Ignore]
[Key]
public string F_Sample_Set_Index { get; set; }
[Ignore]
[Key]
public string A_Sample_ID { get; set; }

[NotMapped]
[Index(0)]
public int Number { get; set; }
[Index(1)]
public string A_Client_Sample_ID { get; set; }
[Index(2)]
public string A_Sample_Type { get; set; }
[Index(3)]
public string A_Sample_Subtype { get; set; }
[Index(4)]
public string A_Latitude { get; set; }
[Index(5)]
public string A_Longitude { get; set; }
[Index(6)]
public string A_Collection_Place { get; set; }
[Index(7)]
public string A_Determined_Elements { get; set; }
[Index(8)]
public string A_Halogens_Plan { get; set; }
[Index(9)]
public string A_Heavy_Metals_Plan { get; set; }
[Index(10)]
public bool A_Short_Lived_Plan { get; set; }
[Index(11)]
public bool A_Long_Lived_Plan { get; set; }
[Index(12)]
public bool A_F_Plan { get; set; }
[Index(13)]
public bool A_Na_Plan { get; set; }
[Index(14)]
public bool A_Mg_Plan { get; set; }
[Index(15)]
public bool A_Al_Plan { get; set; }
[Index(16)]
public bool A_Si_Plan { get; set; }
[Index(17)]
public bool A_S_Plan { get; set; }
[Index(18)]
public bool A_Cl_Plan { get; set; }
[Index(19)]
public bool A_K_Plan { get; set; }
[Index(20)]
public bool A_Ca_Plan { get; set; }
[Index(21)]
public bool A_Sc_Plan { get; set; }
[Index(22)]
public bool A_Ti_Plan { get; set; }
[Index(23)]
public bool A_V_Plan { get; set; }
[Index(24)]
public bool A_Cr_Plan { get; set; }
[Index(25)]
public bool A_Mn_Plan { get; set; }
[Index(26)]
public bool A_Fe_Plan { get; set; }
[Index(27)]
public bool A_Co_Plan { get; set; }
[Index(28)]
public bool A_Ni_Plan { get; set; }
[Index(29)]
public bool A_Cu_Plan { get; set; }
[Index(30)]
public bool A_Zn_Plan { get; set; }
[Index(31)]
public bool A_Ga_Plan { get; set; }
[Index(32)]
public bool A_Ge_Plan { get; set; }
[Index(33)]
public bool A_As_Plan { get; set; }
[Index(34)]
public bool A_Se_Plan { get; set; }
[Index(35)]
public bool A_Br_Plan { get; set; }
[Index(36)]
public bool A_Rb_Plan { get; set; }
[Index(37)]
public bool A_Sr_Plan { get; set; }
[Index(38)]
public bool A_Y_Plan { get; set; }
[Index(39)]
public bool A_Zr_Plan { get; set; }
[Index(40)]
public bool A_Nb_Plan { get; set; }
[Index(41)]
public bool A_Mo_Plan { get; set; }
[Index(42)]
public bool A_Ru_Plan { get; set; }
[Index(43)]
public bool A_Pd_Plan { get; set; }
[Index(44)]
public bool A_Ag_Plan { get; set; }
[Index(45)]
public bool A_Cd_Plan { get; set; }
[Index(46)]
public bool A_In_Plan { get; set; }
[Index(47)]
public bool A_Sn_Plan { get; set; }
[Index(48)]
public bool A_Sb_Plan { get; set; }
[Index(49)]
public bool A_I_Plan { get; set; }
[Index(50)]
public bool A_Cs_Plan { get; set; }
[Index(51)]
public bool A_Ba_Plan { get; set; }
[Index(52)]
public bool A_La_Plan { get; set; }
[Index(53)]
public bool A_Ce_Plan { get; set; }
[Index(54)]
public bool A_Pr_Plan { get; set; }
[Index(55)]
public bool A_Nd_Plan { get; set; }
[Index(56)]
public bool A_Sm_Plan { get; set; }
[Index(57)]
public bool A_Eu_Plan { get; set; }
[Index(58)]
public bool A_Gd_Plan { get; set; }
[Index(59)]
public bool A_Tb_Plan { get; set; }
[Index(60)]
public bool A_Dy_Plan { get; set; }
[Index(61)]
public bool A_Ho_Plan { get; set; }
[Index(62)]
public bool A_Er_Plan { get; set; }
[Index(63)]
public bool A_Tm_Plan { get; set; }
[Index(64)]
public bool A_Yb_Plan { get; set; }
[Index(65)]
public bool A_Lu_Plan { get; set; }
[Index(66)]
public bool A_Hf_Plan { get; set; }
[Index(67)]
public bool A_Ta_Plan { get; set; }
[Index(68)]
public bool A_W_Plan { get; set; }
[Index(69)]
public bool A_Re_Plan { get; set; }
[Index(70)]
public bool A_Os_Plan { get; set; }
[Index(71)]
public bool A_Ir_Plan { get; set; }
[Index(72)]
public bool A_Pt_Plan { get; set; }
[Index(73)]
public bool A_Au_Plan { get; set; }
[Index(74)]
public bool A_Hg_Plan { get; set; }
[Index(75)]
public bool A_Th_Plan { get; set; }
[Index(76)]
public bool A_U_Plan { get; set; }
[Index(77)]
public string A_Notes { get; set; }
}
}
72 changes: 38 additions & 34 deletions Forms/Form_ElsSum.vb
Original file line number Diff line number Diff line change
Expand Up @@ -177,44 +177,48 @@ Public Class Form_ElsSum
End Sub

Function FormFinalFilesDict(ByVal type As String, ByRef gYear As String) As Dictionary(Of String, String)
Debug.WriteLine("Started to form final files array:")
LabelStatus.Text = "Формирование имен загружаемых файлов..."
Dim finArr = New Dictionary(Of String, String)
Dim finSrmsArr = New Dictionary(Of String, String)
Dim typeFtp As New Dictionary(Of String, String)
Dim dtStrCont As String = ""
Dim dt As New DateTime()
typeFtp.Add("КЖИ", "kji")
typeFtp.Add("ДЖИ-1", "dji-1")
typeFtp.Add("ДЖИ-2", "dji-2")
Dim setKey As String = $"{LablelElSumCountryCode.Text}-{LabelElSumClientId.Text}-{LabelElSumYear.Text}-{LabelElSumSetId.Text}-{LabelElSumSetIndex.Text}"

For Each row As DataGridViewRow In DataGridViewElsSum.Rows
Dim cellFile As DataGridViewCell = row.Cells($"Файлы спектров {type}")
If String.IsNullOrEmpty(cellFile.Value.ToString) Then Continue For
Dim cellDate As DataGridViewCell = row.Cells($"{typeFtp(type)}-Date")
Dim loadNumCell As DataGridViewCell = row.Cells($"loadNumber")
If String.IsNullOrEmpty(cellDate.Value.ToString) Then Continue For
dt = Convert.ToDateTime(cellDate.Value)
If (Not dtStrCont.Contains($"{dt.ToShortDateString}-{row.Cells("Container_Number").Value}")) Then dtStrCont += $"'{dt.ToShortDateString}-{row.Cells("Container_Number").Value}',"
Try
Debug.WriteLine("Started to form final files array:")
LabelStatus.Text = "Формирование имен загружаемых файлов..."
Dim finArr = New Dictionary(Of String, String)
Dim finSrmsArr = New Dictionary(Of String, String)
Dim typeFtp As New Dictionary(Of String, String)
Dim dtStrCont As String = ""
Dim dt As New DateTime()
typeFtp.Add("КЖИ", "kji")
typeFtp.Add("ДЖИ-1", "dji-1")
typeFtp.Add("ДЖИ-2", "dji-2")
Dim setKey As String = $"{LablelElSumCountryCode.Text}-{LabelElSumClientId.Text}-{LabelElSumYear.Text}-{LabelElSumSetId.Text}-{LabelElSumSetIndex.Text}"

For Each row As DataGridViewRow In DataGridViewElsSum.Rows
Dim cellFile As DataGridViewCell = row.Cells($"Файлы спектров {type}")
If String.IsNullOrEmpty(cellFile.Value.ToString) Then Continue For
Dim cellDate As DataGridViewCell = row.Cells($"{typeFtp(type)}-Date")
Dim loadNumCell As DataGridViewCell = row.Cells($"loadNumber")
If String.IsNullOrEmpty(cellDate.Value.ToString) Then Continue For
dt = Convert.ToDateTime(cellDate.Value)
If (Not dtStrCont.Contains($"{dt.ToShortDateString}-{row.Cells("Container_Number").Value}")) Then dtStrCont += $"'{dt.ToShortDateString}-{row.Cells("Container_Number").Value}',"

If type.Contains("ДЖИ") Then
Debug.WriteLine($"{setKey}\{loadNumCell.Value}\{typeFtp(type)}\c-{row.Cells("Container_Number").Value}\samples\{row.Cells($"Файлы спектров {type}").Value}.cnf")
finArr.Add(row.Cells($"Файлы спектров {type}").Value, $"{setKey}\{loadNumCell.Value}\{typeFtp(type)}\c-{row.Cells("Container_Number").Value}\samples\{row.Cells($"Файлы спектров {type}").Value}.cnf")
Else
Debug.WriteLine($"{setKey}\{typeFtp(type)}\samples\{row.Cells($"Файлы спектров {type}").Value}.cnf")
finArr.Add(row.Cells($"Файлы спектров {type}").Value, $"{setKey}\{typeFtp(type)}\samples\{row.Cells($"Файлы спектров {type}").Value}.cnf")
GetRelatedSLISRMs(finSrmsArr, setKey, dt)
End If
Next

If type.Contains("ДЖИ") Then
Debug.WriteLine($"{setKey}\{loadNumCell.Value}\{typeFtp(type)}\c-{row.Cells("Container_Number").Value}\samples\{row.Cells($"Файлы спектров {type}").Value}.cnf")
finArr.Add(row.Cells($"Файлы спектров {type}").Value, $"{setKey}\{loadNumCell.Value}\{typeFtp(type)}\c-{row.Cells("Container_Number").Value}\samples\{row.Cells($"Файлы спектров {type}").Value}.cnf")
Else
Debug.WriteLine($"{setKey}\{typeFtp(type)}\samples\{row.Cells($"Файлы спектров {type}").Value}.cnf")
finArr.Add(row.Cells($"Файлы спектров {type}").Value, $"{setKey}\{typeFtp(type)}\samples\{row.Cells($"Файлы спектров {type}").Value}.cnf")
GetRelatedSLISRMs(finSrmsArr, setKey, dt)
GetRelatedLLISRMs(finSrmsArr, setKey, typeFtp(type), dtStrCont.Substring(0, dtStrCont.Length - 1))
End If
Next

If type.Contains("ДЖИ") Then
GetRelatedLLISRMs(finSrmsArr, setKey, typeFtp(type), dtStrCont.Substring(0, dtStrCont.Length - 1))
End If

gYear = Convert.ToDateTime(DataGridViewElsSum.Rows(0).Cells($"{typeFtp(type)}-Date").Value).Year.ToString()
Debug.WriteLine($"Guessed year: {gYear}")
Return finArr.Union(finSrmsArr).ToDictionary(Function(p) p.Key, Function(p) p.Value)
gYear = Convert.ToDateTime(DataGridViewElsSum.Rows(0).Cells($"{typeFtp(type)}-Date").Value).Year.ToString()
Debug.WriteLine($"Guessed year: {gYear}")
Return finArr.Union(finSrmsArr).ToDictionary(Function(p) p.Key, Function(p) p.Value)
Catch ex As Exception
Return New Dictionary(Of String, String)
End Try
End Function

Function FindFiles(ByRef names As Dictionary(Of String, String).KeyCollection, ByVal gYear As String) As Dictionary(Of String, String)
Expand Down
1 change: 1 addition & 0 deletions Forms/Form_Sample_Accept.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions Forms/Form_Sample_Accept.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,6 @@
<metadata name="Table_Received_By_BindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>617, 24</value>
</metadata>
<metadata name="Table_Received_By_BindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>617, 24</value>
</metadata>
<metadata name="NAA_DB_EXPDataSet.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="NAA_DB_EXPDataSet.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
Expand Down
Loading

0 comments on commit ec2dced

Please sign in to comment.