데이터 정리 완료

This commit is contained in:
김판돌 2023-11-19 20:50:43 +09:00
parent 47cad5c7e3
commit 4359369a91
7 changed files with 107 additions and 40 deletions

View File

@ -7,9 +7,9 @@ namespace Server.Git
public abstract class AbstractGit
{
public bool isRestart;
string repositoryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "excel");
string _repositoryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "excel");
public string _repositoryPath { get { return repositoryPath; } }
public string repositoryPath { get { return _repositoryPath; } }
/// <summary>
/// 가장먼저 시작해야 하는 스크립트
@ -36,18 +36,18 @@ namespace Server.Git
private void Pull()
{
if (!Directory.Exists(repositoryPath))
if (!Directory.Exists(_repositoryPath))
{
Directory.CreateDirectory(repositoryPath);
RepositorySet($"clone {STATICS.remoteUrl} {repositoryPath}", null);
Directory.CreateDirectory(_repositoryPath);
RepositorySet($"clone {STATICS.remoteUrl} {_repositoryPath}", null);
//main브렌치로 세팅
RepositorySet("branch -m main", repositoryPath);
RepositorySet("branch --set-upstream-to=origin/main main", repositoryPath);
RepositorySet("branch -m main", _repositoryPath);
RepositorySet("branch --set-upstream-to=origin/main main", _repositoryPath);
}
// pull 명령어 실행
RepositorySet("pull", repositoryPath);
RepositorySet("pull", _repositoryPath);
}
private static void RepositorySet(string command, string workingDirectory)

View File

@ -1,25 +1,43 @@
using Aspose.Cells;
using NLog;
namespace Server.Git
{
class ExcelManager
{
Dictionary<int, Dictionary<int, List<string>>> _dicViewer;
private static readonly NLog.ILogger logger = LogManager.GetCurrentClassLogger();
public class sheet
{
string _name;
public string name { get { return _name; } }
List<string> _variable;
public List<string> variable { get { return _variable; } }
List<string> _type;
public List<string> type { get { return _type; } }
Dictionary<int, List<object>> _dicViewer;
public Dictionary<int, List<object>> dicViewer { get { return _dicViewer; } }
public sheet(string name, List<string> variable, List<string> type, Dictionary<int, List<object>> dicViewer)
{
this._name = name;
this._variable = variable;
this._type = type;
this._dicViewer = dicViewer;
}
}
List<sheet> _sheets;
public List<sheet> sheets { get { return _sheets; } }
string _pathFile;
public ExcelManager(string path, string file)
{
_pathFile = path + "\\" + file;
Console.WriteLine(_pathFile);
_dicViewer = new Dictionary<int, Dictionary<int, List<string>>>();
}
public Dictionary<int, Dictionary<int, List<string>>> dicViewerOut
{
get { return _dicViewer; }
}
public void Play()
public bool Play()
{
ExcelLoad(_pathFile);
return ExcelLoad(_pathFile);
}
public bool ExcelLoad(string path)//엑셀 로드
{
@ -29,34 +47,67 @@ namespace Server.Git
// 모든 워크시트 가져오기
WorksheetCollection collection = wb.Worksheets;
_sheets = new List<sheet>();
// 모든 워크시트 반복
try
{
for (int worksheetIndex = 0; worksheetIndex < collection.Count; worksheetIndex++)
{
//변수이름
List<string> variable = new List<string>();
//변수 타입
List<string> type = new List<string>();
Dictionary<int, List<object>> dicViewer = new Dictionary<int, List<object>>();
// 인덱스를 사용하여 워크시트 가져오기
Worksheet worksheet = collection[worksheetIndex];
// 워크시트 이름 인쇄
Console.WriteLine("Worksheet: " + worksheet.Name);
// 행과 열의 수 얻기
int rows = worksheet.Cells.MaxDataRow;
int cols = worksheet.Cells.MaxDataColumn;
int vertical = worksheet.Cells.MaxDataRow;
int horizontal = worksheet.Cells.MaxDataColumn;
// 행 반복
for (int i = 0; i < rows; i++)
//변수 이름과 타입 삽입
for (int n = 0; n <= horizontal; n++)
{
// Console.Write(worksheet.Cells[i, j].Value + " | ");
variable.Add((string)worksheet.Cells[0, n].Value);
type.Add(((string)worksheet.Cells[2, n].Value).ToLower());
}
// 선택한 행의 각 열 반복
for (int j = 0; j < cols; j++)
for (int n = 3; n <= vertical; n++)
{
// 프링 셀 값
Console.Write(worksheet.Cells[i, j].Value + " | ");
}
// 줄바꿈 인쇄
Console.WriteLine(" ");
List<object> dataList = new List<object>();
for (int m = 0; m <= horizontal; m++)
{
switch (type[m])
{
case "enum":
case "int":
dataList.Add(worksheet.Cells[n, m].Value);
break;
case "string":
case "text":
case "time":
dataList.Add(worksheet.Cells[n, m].Value);
break;
default:
Console.WriteLine("알수없는 타입의 메세지 입니다.");
break;
}
}
dicViewer.Add(n, dataList);
}
sheet sheet = new sheet(worksheet.Name, variable, type, dicViewer);
_sheets.Add(sheet);
}
}
catch (Exception ex)
{
logger.Error(ex);
return false;
}
return true;
}
}

View File

@ -10,10 +10,26 @@
//데이터 db에 업로드
//json화된 데이터 push
ExcelManager em = new ExcelManager(_repositoryPath, "TESTexl.xlsx");
em.Play();
ExcelManager em = new ExcelManager(repositoryPath, "TESTexl.xlsx");
if (em.Play())
{
List<ExcelManager.sheet> sheets = em.sheets;
foreach (KeyValuePair<int, List<object>> sheet in sheets[0].dicViewer)
{
foreach (object obj in sheet.Value)
{
//이것을 기반으로 서버 테이블을 생성뒤 데이터를 세팅
//Console.WriteLine(obj);
}
}
}
else
{
Console.WriteLine("-1 : NotUpdate");
}
Console.WriteLine("집에가고싶다아");
//db에 데이터를올리는것은 이곳에 작성할 예정

Binary file not shown.

Binary file not shown.