Commit 5dc498e7 authored by datdiep's avatar datdiep

Update Program.cs

parent cd3fa7af
using OfficeOpenXml;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace testImport
{
public class excel_template
{
public Guid id { get; set; }
public string name { get; set; }
public string code { get; set; }
public string type { get; set; }
}
public class customer_template
{
public Guid id { get; set; }
public Guid customer_id { get; set; }
public Guid id_excel_template { get; set; }
public int sheet { get; set; }
public string coordinate { get; set; }
public int order { get; set; }
public Guid id_sub { get; set; }
public int body { get; set; }
public int merge { get; set; }
}
public class subdetail
{
public Guid id { get; set; }
public Guid id_excel_template { get; set; }
public int row { get; set; }
}
public class saved
{
public Guid id { get; set; }
public Guid id_excel_template { get; set; }
public Guid user_id { get; set; }
public string value { get; set; }
public DateTime Time { get; set; }
public DateTime created { get; set; }
public string tmp { get; set; }
}
public class Program
{
public static void Main(string[] args)
{
List<excel_template> excel_Templates;
List<customer_template> customer_Templates;
List<subdetail> Subdetails;
Data x = new Data();
excel_Templates = x.fakeData().Item1;
customer_Templates = x.fakeData().Item2;
Subdetails = x.fakeData().Item3;
int BODY = customer_Templates.FirstOrDefault().body;
int SEED = customer_Templates.FirstOrDefault().merge;
//count sheet
var _MAXSHEET = customer_Templates.Max(c => c.sheet);
var firstSheet = 0;
//variable ?
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
var filePath = @"C:\Users\Admin\Downloads\HR_SK.xlsx";
byte[] file = File.ReadAllBytes(filePath);
List<saved> XX = new List<saved>();
using (MemoryStream stream = new MemoryStream(file))
{
using (ExcelPackage excelPackage = new ExcelPackage(stream))
{
while (firstSheet == _MAXSHEET)
{
var DataSheet = excelPackage.Workbook.Worksheets[firstSheet];
for (int i = 108; i <= DataSheet.Dimension.End.Row - Convert.ToInt32(BODY); i+=SEED) //i+=seed
{
//check last: if STT is not number => stop
var testLast = DataSheet.Cells["A" + (Convert.ToInt32(BODY) + i).ToString()].Value is null ? " " : DataSheet.Cells["A" + (Convert.ToInt32(BODY) + i).ToString()].Value.ToString();
if (!int.TryParse(testLast, out _)) //https://stackoverflow.com/questions/894263/identify-if-a-string-is-a-number
break;
foreach (var value in customer_Templates.Where(c => c.sheet == firstSheet).ToList())
{
var Address = value.coordinate as String + (Convert.ToInt32(BODY) + i).ToString();
if (!value.coordinate.Contains(":"))
{
string xxxxx = DataSheet.Cells[Address].Value is null ? "" : DataSheet.Cells[Address].Value.ToString();
saved save = new saved();
save.value = xxxxx;
save.id_excel_template = value.id_excel_template;
XX.Add(save);
}
else
{
var split = value.coordinate.Split(":");
int countsub = 4; //count list on db
for(int ii = 0; ii < countsub; ii++)
{
Address = split[0] + (Convert.ToInt32(BODY) + i + ii).ToString() + ":" + split[1] + (Convert.ToInt32(BODY) + i + ii).ToString();
var range = DataSheet.Cells[Address];
foreach (var rangeBasse in range)
{
saved save = new saved();
string xxx = rangeBasse.Value is null ? "" : rangeBasse.Value.ToString();
save.value = xxx;
save.id_excel_template = value.id_excel_template;
var tmpx = new[] { "vào", "ra", "tăng ca", "tông công" };
save.tmp = tmpx[ii];
XX.Add(save);
}
}
}
}
}
firstSheet++;
}
}
}
Console.WriteLine("xxx");
}
}
}
using OfficeOpenXml;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace testImport
{
public class excel_template
{
public Guid id { get; set; }
public string name { get; set; }
public string code { get; set; }
public string type { get; set; }
}
public class customer_template
{
public Guid id { get; set; }
public Guid customer_id { get; set; }
public Guid id_excel_template { get; set; }
public int sheet { get; set; }
public string coordinate { get; set; }
public int order { get; set; }
public Guid id_sub { get; set; }
public int body { get; set; }
public int merge { get; set; }
}
public class subdetail
{
public Guid id { get; set; }
public Guid id_excel_template { get; set; }
public int row { get; set; }
}
public class saved
{
public Guid id { get; set; }
public Guid id_excel_template { get; set; }
public Guid user_id { get; set; }
public string value { get; set; }
public DateTime Time { get; set; }
public DateTime created { get; set; }
public string tmp { get; set; }
}
public class Program
{
public static void Main(string[] args)
{
List<excel_template> excel_Templates;
List<customer_template> customer_Templates;
List<subdetail> Subdetails;
Data x = new Data();
excel_Templates = x.fakeData().Item1;
customer_Templates = x.fakeData().Item2;
Subdetails = x.fakeData().Item3;
int BODY = customer_Templates.FirstOrDefault().body;
int SEED = customer_Templates.FirstOrDefault().merge;
//count sheet
var _MAXSHEET = customer_Templates.Max(c => c.sheet);
var firstSheet = 0;
//variable ?
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
var filePath = @"C:\Users\Admin\Downloads\HR_SK.xlsx";
byte[] file = File.ReadAllBytes(filePath);
List<saved> XX = new List<saved>();
using (MemoryStream stream = new MemoryStream(file))
{
using (ExcelPackage excelPackage = new ExcelPackage(stream))
{
while (firstSheet == _MAXSHEET)
{
var DataSheet = excelPackage.Workbook.Worksheets[firstSheet];
for (int i = 108; i <= DataSheet.Dimension.End.Row - Convert.ToInt32(BODY); i+=SEED) //i+=seed
{
//check last: if STT is not number => stop
var testLast = DataSheet.Cells["A" + (Convert.ToInt32(BODY) + i).ToString()].Value is null ? " " : DataSheet.Cells["A" + (Convert.ToInt32(BODY) + i).ToString()].Value.ToString();
if (!int.TryParse(testLast, out _)) //https://stackoverflow.com/questions/894263/identify-if-a-string-is-a-number
break;
foreach (var value in customer_Templates.Where(c => c.sheet == firstSheet).ToList())
{
var Address = value.coordinate as String + (Convert.ToInt32(BODY) + i).ToString();
if (!value.coordinate.Contains(":"))
{
string xxxxx = DataSheet.Cells[Address].Value is null ? "" : DataSheet.Cells[Address].Value.ToString();
saved save = new saved();
save.value = xxxxx;
save.id_excel_template = value.id_excel_template;
XX.Add(save);
}
else
{
var split = value.coordinate.Split(":");
int countsub = 4; //count list on db
for(int ii = 0; ii < countsub; ii++)
{
Address = split[0] + (Convert.ToInt32(BODY) + i + ii).ToString() + ":" + split[1] + (Convert.ToInt32(BODY) + i + ii).ToString();
var range = DataSheet.Cells[Address];
foreach (var rangeBasse in range)
{
saved save = new saved();
string xxx = rangeBasse.Value is null ? "" : rangeBasse.Value.ToString();
save.value = xxx;
save.id_excel_template = Subdetails[ii].id_excel_template;
var tmpx = new[] { "vào", "ra", "tăng ca", "tông công" };
save.tmp = tmpx[ii];
XX.Add(save);
}
}
}
}
}
firstSheet++;
}
}
}
Console.WriteLine("xxx");
}
}
}
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