thewar_server/Server/Git/XlsxToJson.cs

70 lines
3.2 KiB
C#

using Newtonsoft.Json;
namespace Server.Git
{
public class XlsxToJson : AbstractGit
{
public override string ChangeScript()
{
//저장경로 : repositoryPath
List<string> fileList = GetFiles(repositoryPath, ".xlsx");
Dictionary<string, Dictionary<long, Dictionary<string, object>>> clientSheetList = new Dictionary<string, Dictionary<long, Dictionary<string, object>>>();
List<Sheet> serverSheetList = new List<Sheet>();
for (int n = 0; n < fileList.Count; n++)
{
ExcelManager em = new ExcelManager(fileList[n]);
if (em.Play())
{
sheets = em.sheets;
for (int m = 0; m < sheets.Count; m++)
{
switch (sheets[m].dataEnum[0])
{
case "server":
serverSheetList.Add(new Sheet(sheets[m]));
break;
case "client":
clientSheetList.Add(sheets[m].name, sheets[m].dicViewer);
break;
case "all":
//수정할것 이렇게 작업되면 데이터가 2개로 나눠지는것이 아닌 한개의 데이터가 중복으로 제거됨.
Sheet sheet = new Sheet(sheets[m]);
string name = sheet.name;
//서버는 다른곳에서 처리를 하기때문에 여기서는 add만 시켜줌.
serverSheetList.Add(new Sheet(sheets[m]));
Dictionary<long, Dictionary<string, object>> clientSheet = sheet.dicViewer;
for (int i = 1; i < sheet.dataEnum.Count; i++)
{
if (sheet.dataEnum[i] == "server")
{
foreach (var item in clientSheet)
{
item.Value.Remove(sheet.variable[i]);
}
}
}
clientSheetList.Add(name, clientSheet);
break;
}
}
}
else
{
//Console.WriteLine("-1 : NotUpdate");
return "";
}
}
//현재 서버는 PostgreSQL기준으로 쿼리를 생성하는 코드와 패키지가 세팅되어 있습니다 이점 참고바랍니다
//추가로 해당 기능을 사용하려면 서버에 excel이라는 스키마가 존재하여야 합니다.
if (sheets != null && serverSheetList.Count != 0)
{
ExcelSQL sql = new ExcelSQL(serverSheetList);
sql.DataUpdate();
}
return JsonConvert.SerializeObject(clientSheetList);
}
}
}